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?

  • 5
    $\begingroup$ I'm curious $-$ why do you need to do this? $\endgroup$ – TonyK Jul 26 '16 at 9:59
  • 1
    $\begingroup$ It would probably be faster to wait a couple of hundred years for technology improvements. $\endgroup$ – barak manos Jul 26 '16 at 10:00
  • 1
    $\begingroup$ 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 $\endgroup$ – Dis-integrating Jul 26 '16 at 10:34
  • 1
    $\begingroup$ maybe you can find some hints here: luschny.de/math/factorial/FastFactorialFunctions.htm $\endgroup$ – miracle173 Jul 26 '16 at 10:36
  • 1
    $\begingroup$ 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 $\endgroup$ – Yuriy S Jul 26 '16 at 10:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.