1

Is there any way to calculate the factorial of N, where N>200.Is there something like Bigdata in c++.Since even a long variable cannot store such a big number.can you please tell me any approach to deal with such big number problems????

Saurabh Saluja
  • 190
  • 1
  • 9
  • 3
    Not in standard C++, but there are libraries out there just waiting. – chris Mar 28 '14 at 20:37
  • 1
    see http://stackoverflow.com/questions/12988099/big-numbers-library-in-c – denis-bu Mar 28 '14 at 20:39
  • 1
    see also http://stackoverflow.com/questions/117429/handling-large-numbers-in-c and, I'm sure, a dozen others... google would have saved you time. – mah Mar 28 '14 at 20:40
  • The [GNU GMP](https://gmplib.org/) library is popular, as is OpenSSL's [BN](https://www.openssl.org/docs/crypto/bn.html). – David Schwartz Mar 28 '14 at 20:44

2 Answers2

1

int or long types are not big enough for the values you're talking about.

34! = 295232799039604140847618609643520000000

This barely fits into 128 bits. If your compiler supports a 128-bit number type, you can use it to calculate factorials up to 34. If not, or if you need anything larger, you will need to use some kind of bignum library.

See this question for bignum libraries: Big numbers library in c++

Community
  • 1
  • 1
1

I implemented a BigInteger for C++. You are welcome to use it.

http://memmove.blogspot.com/2013/04/unlimited-unsigned-integer-in-c.html

Jonathan Henson
  • 8,076
  • 3
  • 28
  • 52