Factorial number of digits
Is there any neat way to solve how many digits the number $20!$ have? I'm looking a solution which does not use computers, calculators nor log tables, just pen and paper.
I come from a background in computers, so here's my two cents. Taking the logarithm to the base 10 of n!. If the log comes out to be x, it is not hard to see that the number of digits must be the lowest integer greater than or equal to x, i.e, $floor(x)+1$. Now the question comes down to approximating the $log(n!)$ It is possible to prove by induction that n! lies between $(\frac{n}{2})^n$ and $(\frac{n}{3})^n$. Thus the log(n!) lies between $nlog(\frac{n}{2})$ and $nlog(\frac{n}{3})$. We can get a pretty tight bound if we used log tables for log(20/3), but as you have disallowed that, using the upper limit(which becomes log(10) = 1) will do quite nicely too. The answer comes to 20*log(10) = 20, which should tell you that the expected number of digit is about 19 or 20.(Since 20 is only the upper bound). And 19 happens to be the answer.
There is unclean way of solving it.
Number of digits in a number 'N' is CEILING(log(N))
.
So number of digit in N!
is CEILING(log(N!)) = CEILING(log(N*(N-1)*(N-2)) ... 2*1)
Thus,
CEILING(log(N!)) = CEILING(log(N) + log(N-1) +log(N-2)+ ... log(2)*log(1))
Which is pretty easy to compute.
Source: http://pitcher.digitalfreehold.ca/code/computeSize
As a rough approximation, multiplying an $n$-digit number by an $m$-digit number yields a result with about $n+m$ digits. So the numbers from 2 to 9 are all 1-digit numbers. From 10 to 20 are all 2-digit numbers. That suggests we should have about 18 digits or so.
Wolfram|Alpha claims that $20! = 2.4 \times 10^{18}$. Not far off! :-D
I will use log as the base b logarithm and ln as the natural log.
Then number of digits of x in base b is given by one more than the floor of the log(x).
log(n!)=sum(log(k)) for k=1,2,...,n
We can interpret this as the Riemann sum for the integral from 1 to n of log(x) dx. This integral is actually a lower bound. The upper bound is the same integral from 2 to n+1 rather than 1 to n.
The lower bound integral is given by n log(n)-(n-1)/ln(b). The upper bound gives (n+1) log(n+1)-n/ln(b) -2ln(2)+1/ln(b).
For n=20, working in base 10, we get about 17.8 as the lower bound and 18.9 as the upper bound. One more than the floor gives 18 or 19 digits. Not surprisingly, the answer is 19 as the lower bound is nearly 19 digits and the upper is nearly 20.
The Riemann sum approximations will get better as n increases, but the answer is already quite good by n=20.