When does $n!$ have exactly $n$ zeroes?

143 Views Asked by At

The number of digits in $n!$ grows as $n\log n$, and some roughly fixed fraction of those are zeroes, so $n!$ will tend to have fewer than $n$ zeroes for small $n$ and greater than $n$ zeroes for large $n$. Can anyone split the difference and find the exact solution(s)? If this is infeasible in base $10$, can you do it for smaller bases?

2

There are 2 best solutions below

2
On

For all bases, the only time $n!$ has exactly $n$ zeros is $n=0$.

$$0! = 1$$

To see why, we are essentially counting the number of 5's in the prime factorization (2's are plentiful), and $n!$ has exactly $\sum_{i=1}^\infty \left\lfloor\frac{n}{5^i}\right\rfloor$ in its factorization (Landau 1900). Thus, we solve

$$ n = \sum_{i=1}^\infty \left\lfloor\frac{n}{5^i}\right\rfloor $$ which is only true for $n = 0$. It's the exact same story for smaller bases.

5
On

Heuristically: we have $\approx \frac n4$ trailing zeroes at the end of $n!$ (as Jaideep Khare's answer notes); by Stirling's approximation there are (very) roughly $\log_{10}\left(\left(\frac ne\right)^n\right)\approx n\log_{10}n-.43n$ total digits in $n!$. Of the $n\log_{10}n-.68n$ remaining digits (i.e., the digits that aren't part of the trailing zeroes) we expect $\frac1{10}$ to be zero, so to have $n$ total zeroes we want $\frac1{10}(n\log_{10}n-.68n)=\frac34n$, or $(\frac{30}4+.68)n=n\log_{10}n$, or $\log_{10}n\approx8.18$; thus, looking for $n$ between about $10^7$ and $10^9$ — which should be fairly computer-accessible — should turn up potential candidates.

(If I were to do it, I'd test a few numbers in the general vicinity to make sure that the $\frac1{10}$ heuristic is roughly accurate, then use binary search to narrow down to a smaller plausible range where I could test individual cases. Just computing $n!$ for numbers in this range is going to be challenging; doing it by linear multiplication will take $\Omega(n^2)$ time which is barely on the edge of feasible, so you might need to look at approaches based around the prime factorization and/or CRT-based approaches. Strangely, I can't find any information on the web about computing ultra-large factorials.)