Search code examples
c#factorial

working with very large integers in c#


Does anybody know of a way I can calculate very large integers in c#

I am trying to calculate the factorial of numbers e.g.

5! = 5*4*3*2*1 = 120

with small numbers this is not a problem but trying to calculate the factorial of the bigest value of a unsigned int which is 4,294,967,295 it doesn't seem possible.

I have looked into the BigInteger class but it doesn't seem to do what I need

any help would be greatly appreciated


Solution

  • 4294967295! = 10^(10^10.597) ~ 10^(40000000000) This value requires about 40 Gb of RAM to store, even if you will find any BigInteger implementation for C#!

    P.S. Well, with optimized storing, let's say 9 digits in 4 bytes, it will take ~18 Gb of RAM.