-2

How can we solve equations having N! constants in it , where N can be of range 1<=N<=10^6 BigInteger can only perform upto 128 bits right?

Even when one do logarithm on both sides, it leaves values bigger than BigInteger.

cypronmaya
  • 520
  • 1
  • 11
  • 24
  • 2
    Where does it say "BigInteger can only do 128 bits"? To me, it says "arbitrary precision". – Has QUIT--Anony-Mousse Jan 01 '12 at 11:46
  • BigInteger is only limited by your available memory - unless this is the cause then it'll most likely be a bug with your code that's causing the issue. If you post more details we may be able to help. – Michael Berry Jan 01 '12 at 11:51
  • how can one solve those equations(variables-2) having such a BigInteger constants without bruteforcing? – cypronmaya Jan 01 '12 at 12:54

3 Answers3

7

No, BigInteger can handle arbitrary sizes of integer (limited by memory). From the documentation:

Immutable arbitrary-precision integers.

(Emphasis mine.)

That's not to say that BigInteger will necessarily be the right answer to your requirements, but it's worth being aware of its real capabilities before deciding.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
1

Even when one do logarithm on both sides, it leaves values bigger than BigInteger.

let N=10^6

log(N!) ~ NlogN - N [Stirling's approximation]

        ~ 13e6

this can (easily) fit in int

C. Reed
  • 2,382
  • 7
  • 30
  • 35
  • Sorry to say , but approximation can result wrong integral solutions to an equation right? so.... – cypronmaya Jan 01 '12 at 12:30
  • 1
    For N=100, Stirling's 2nd order approximation is accurate to > 99% and will not change your results noticeably for N > 1000, see e.g. (http://hyperphysics.phy-astr.gsu.edu/hbase/math/stirling.html). You can also carry the approximation out to higher orders (see wikipedia). – C. Reed Jan 01 '12 at 12:42
1

The implementation of BigInteger is limited to around 2 ^ 2.1 billion bits or about 256 MB. Given its used of int for bit lengths, this is unlikely to increase.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130