Here is a riddle someone has been asked in a job interview: How many zero digits are there in 100!?
Well, I found the first 24 quite fast by counting how many times five divides 100! (5 divides 20 times and 25 divides it 4 times).
However, there are more zero digits in the middle of the number (these can be found by hand, by typing factorial(100)
in sage).
My question is whether there is a smart way to determine the number of zero digits in 100!, and more generally in n!.
By the way, this will not affect the job interview as it was finished some time ago.
Answer
You can get a very good estimate by (a) calculating the number of powers of ten in the factorial, (b) estimating the total number of decimal digits (using Stirling's approximation), and (c) assuming all digits except the trailing zeroes are equally likely to have any value. Since there are plenty of powers of 2 to go around, the number of trailing zeroes is equal to the number of powers of five, plus the number of powers of twenty-five, etc.
Tn=∞∑k=1⌊n5k⌋.
The total length as estimated by Stirling's approximation is
Ln=log10n!=nlog10n−nln10+O(lnn).
Combining these, our estimate of the total number of zeroes is
Zn∼Tn+110(Ln−Tn)=910∞∑k=1⌊n5k⌋+110nlog10n−n10ln10+O(lnn).
This turns out to be pretty good. Using WolframAlpha to get the exact values:
nEstimateExactAbs. Error10004814729200010221025340002166214323800045734645721600096319560713200020226202271
The result for n=32000 is fortuitously precise...
No comments:
Post a Comment