How many zeros are at the end of 100!?
An interactive visualization of trailing zeros in factorials.
The key idea
A trailing zero comes from a factor of 10 = 2 × 5.
In a factorial, factors of 2 are abundant, so the limiting factor is how many
5s appear in the prime factorization.
2×
5=
10
Enter n from 1 to 1,000,000.
Legendre's formula
Total trailing zeros
Where do the factors of 5 come from?
Multiples of 5 contribute at least one factor of 5. Multiples of 25 contain an extra factor of 5.
no factor of 5
multiple of 5
multiple of 25 → extra 5
For 100!
⌊100 / 5⌋ = 20
+
⌊100 / 25⌋ = 4
=
24
The four numbers 25, 50, 75, and 100 each contribute a second factor of 5.
So merely counting the 20 multiples of 5 would miss four additional zeros.