$100!$ has 158 digits. How many of them are zeros at the end? You do not need to compute it. By unique factorization, the question is how many factors of $2$ and $5$ are hiding in $1 \cdot 2 \cdot 3 \cdots 100$, and there is a formula for that.
Legendre's formula. For a prime $p$, the exponent of $p$ in $n!$ is $$\left\lfloor \frac{n}{p} \right\rfloor + \left\lfloor \frac{n}{p^{2}} \right\rfloor + \left\lfloor \frac{n}{p^{3}} \right\rfloor + \cdots,$$ where $\lfloor x \rfloor$ is the floor, the largest integer at most $x$. The sum stops once $p^{k} > n$.
Why it works
Worked example: One prime
- $\lfloor 20/2 \rfloor = 10$ multiples of $2$.
- $\lfloor 20/4 \rfloor = 5$ multiples of $4$, $\lfloor 20/8 \rfloor = 2$ of $8$, $\lfloor 20/16 \rfloor = 1$ of $16$.
- Total: $10 + 5 + 2 + 1 = 18$. So $2^{18}$ divides $20!$, and $2^{19}$ does not.
Answer: $18$.
Worked example: Zeros at the end
- Each final zero is a factor $10 = 2 \cdot 5$. There are far more $2$s than $5$s, so count the $5$s.
- $\lfloor 100/5 \rfloor + \lfloor 100/25 \rfloor = 20 + 4 = 24$ (and $125 > 100$).
Answer: $24$ zeros.
Worked example: A composite base
- $12 = 2^{2} \cdot 3$, so each copy of $12$ needs two $2$s and one $3$.
- $2$s in $30!$: $15 + 7 + 3 + 1 = 26$, enough for $13$ copies. $3$s: $10 + 3 + 1 = 14$, enough for $14$ copies.
- The $2$s run out first: $k = 13$.
Answer: $k = 13$.
Common mistake
Key idea