How many digits are there in 100 factorial?
How does one calculate the number of digits?
$\endgroup$ 14 Answers
$\begingroup$Suppose that $x$ is a positive, $n$-digit integer. Note that, $$n-1=\log_{10}(10^{n-1}) \leq \log_{10}(x) < \log_{10}(10^n) = n.$$ Thus, you might compute, the floor of $\log_{10}(100!)$ and add $1$. But \begin{align} \log_{10}(100!) &= \sum_{k=1}^{100} \log_{10}(k) \approx \int_{1}^{100}\log_{10}(t)dt \\ &= \left.\frac{t\ln(t)-t}{\ln(10)}\right|_1^{100} \approx 157.005 \end{align} Thus, the answer ought to be 158.
The reason this can be expected to work is that the integral can be approximated via Riemann sums. In fact, $$\sum_{i=1}^{n} \log_{10}(i) < \int_1^n \log_{10}(t)dt < \sum_{i=2}^n\log(10,i) = \sum_{i=1}^n\log(10,i),$$ as illustrated for $n=20$ in the following picture:
Thus, $$\sum_{i=1}^{n} \log_{10}(i) - \sum_{i=1}^n\log(10,i) < \int_1^n \log_{10}(t)dt - \sum_{i=1}^n\log(10,i) < 0.$$ But, the term on the left is just $\log_{10}(100)=2$. So, the integral is a lower bound for the sum that cannot be more than two off of the actual value. Accounting for the fact that the integral is nearly mid-way between the sums, the error should less than one, which is why we hit he answer exactly.
$\endgroup$ 4 $\begingroup$Stirling's formula gives a good approximation: $$n!\approx\sqrt{2\pi n}\left(\frac{n}{e}\right)^n$$
That is messier, but it helps because I can take the logarithm:
$$\log(n!)\approx \log(\sqrt{2\pi n})+n\log\left(\frac{n}{e}\right)$$
That was the common base-ten logarithm.
The number of digits in $n!$ equals the next integer above $\log(n!)$.
If I were writing a computer program to do it:
$$\left\lfloor\log_{10}(100!)\right\rfloor+1=\left\lfloor\sum_{i=1}^{100}\log_{10}(i)\right\rfloor+1 = 158$$
$\lfloor\log_b(x)\rfloor+1$ calculates the smallest integer power of $b$ which is greater than x. i.e. $$b^{\lfloor\log_b(x)\rfloor} \le x < b^{\lfloor\log_b(x)\rfloor+1}.$$ This is the same as the number of digits in a base-$b$ representation of $x$.
$\endgroup$ 7 $\begingroup$Using a four-operations calculator, you can work as follows:
- start from $2$,
- multiply by increasing integers,
- every time the product exceeds $10$, shift the comma (divide by $10$) and count the shift.
The number of digits will be the number of shifts plus one.
$$\begin{align} &2&0\\ &6&0\\ &2.4&1\\ &1.20&2\\ &7.20&2\\ &5.040&3\\ &4.0320&4\\ &\dots&\dots\\ &9.3326215\dots&157 \end{align}$$
Actually, you are computing $100!$ in the scientific notation.
$\endgroup$ 2