# Accurately calculating large factorials

I need to calculate the exact value of $1,000,000,000!$ It can't be an approximation. As far as I am aware, the only way to do this would be to calculate it starting from the beginning $(1\cdot2\cdot3\cdot\cdots\cdot1,000,000,000)$.

So, I have a program setup to do this, and I improved performance a small amount by grabbing the next 100 numbers, multiplying them together, doing that 100 times, then multiplying them together again, and finally multiplying the result by the running factorial. For example, I am currently at $390,000$. so what the program is doing next is grabbing $390,001$ thru $390,100$ and multiplying those together, repeating this until it reaches $400,000$. At that point it will multiply the numbers from each 100 step together, and multiply that result by the factorial of $390,000$.

So, doing it this way is still way too slow. Is there a better way I could do this?

• I'm curious $-$ why do you need to do this? – TonyK Jul 26 '16 at 9:59
• It would probably be faster to wait a couple of hundred years for technology improvements. – barak manos Jul 26 '16 at 10:00
• Also, maybe since the prime factorisation of a factorial is a lot simpler (just take the sum $[\frac{n}{p^k}]$ from $k=1$ to infinity (or n). Where $[x]$ is the floor function for all primes up to $\frac{n}{2}$. This will give you the exponent of the prime factor.) I don't know but maybe it'll make it quicker – Dis-integrating Jul 26 '16 at 10:34
• maybe you can find some hints here: luschny.de/math/factorial/FastFactorialFunctions.htm – miracle173 Jul 26 '16 at 10:36
• I can't imagine any possible application where you need this exact value. For numbers this large Stirling's approximation will do a great job – Yuriy S Jul 26 '16 at 10:57