Someone on
Quora wanted to know if you could compute 1,000,000,000! (one billion factorial) on a computer without the computer blowing up and catching fire. I said sure, though you would need some storage space as the result of such a computation would be roughly 9.5 billion digits long. And then someone else asked how long that would take, and that's a little harder to figure out. There are any number of computing problems that would take zillions of years to complete. Is this one of them? I don't think so, so I wrote a
program using the
GMP library to check. Every 100,000 numbers, it posts the elapsed time. Dennis put it into a graph.
|
Computing 1,000,000 Factorial X Axis is the number divided by 100,000 Y Axis is the number of seconds |
Evaluating 1.6932x^2 + 0.1023x - 0.75 with x set to one billions gives us 1.6932e18 seconds. You will notice that only the first term of that polynomial has any bearing on the result. The second and third terms are down in the noise. It
works out to be 53 billion years. So the real answer to the original question is no.
Of course, if you could line up a billion super fast processors you could knock that down to 53 years, and if you figure out a more efficient algorithm, you could probably cut that in half. Still, it would take a very long time and all you would get would be a really long string of digits.
n! can be evaluated with time complexity O(log log n M (n log n)), where M(n) is the complexity of multiplying two n-digit numbers together.
ReplyDeletecf. Borwein, 1983
watch movies online comedy
ReplyDelete