some problems require a number thats too big for java to handle, and then i cant find the solution even though my code was most likely correct, which is quite annoying to me
correction: a lot of problems require a number that is too big
some problems require a number thats too big for java
-
theoremgoat
- Posts: 3
- Joined: Sat Oct 23, 2021 12:56 am
-
whatteaux
- Posts: 12
- Joined: Mon Sep 24, 2012 11:58 am
Re: some problems require a number thats too big for java
Java can handle arbitrarily large integers, with java.math.BigInteger
- jaap
- Posts: 588
- Joined: Tue Mar 25, 2008 3:57 pm
- Contact:
Re: some problems require a number thats too big for java
Many problems that at first sight require very large numbers can be solved using long integers (<2^63) only. Especially when the answer being asked for is modulo some large number that fits into a long integer.
-
theoremgoat
- Posts: 3
- Joined: Sat Oct 23, 2021 12:56 am
Re: some problems require a number thats too big for java
that BigInteger and long integer dont really work that well in my opinion, in my experience they didnt help me further or get me the correct solution
maybe i have to learn a new programming language that allows me to do things with large numbers.
maybe i have to learn a new programming language that allows me to do things with large numbers.
-
pjt33
- Posts: 140
- Joined: Mon Oct 06, 2008 6:14 pm
Re: some problems require a number thats too big for java
Java's BigInteger is clumsy to use, but if it didn't help you get further with whichever problem prompted the initial post then switching language is probably not the solution. There are PE problems where a naïve approach of calculating everything with BigInteger and applying the modulo M at the very end requires gigabytes of memory for the BigInteger, but that can always be worked around by applying the modulo M to intermediate calculations as well.
-
theoremgoat
- Posts: 3
- Joined: Sat Oct 23, 2021 12:56 am
Re: some problems require a number thats too big for java
no actually, BigInteger does help in some cases (not all), its just something clumsy to use indeed, but i feel like its the only way. but it has helped me some solve problems that normal integer wouldnt.
-
RichardDL
- Posts: 3
- Joined: Sat Mar 16, 2019 3:56 pm
Re: some problems require a number thats too big for java
I use BigInteger, it's a bit clunky compared with normal coding but has always worked. Successful on 5 problems between 50 and 70.
-
noZemSagogo
- Posts: 1
- Joined: Thu May 07, 2020 4:35 pm
Re: some problems require a number thats too big for java
I'm more of a math person so I found this frustrating at first also, but the problems are meant to provoke you to find creative workarounds in your language of choice.
