Zeros at the End of 100!

  • Medium
  • Number puzzles
  • Tests: Counting factors instead of multiplying

The puzzle

100! means 1 x 2 x 3 x ... x 100. The result is a 158-digit number ending in a run of zeros.

How many zeros are at the end? You are not expected to compute the product.

Stuck?

One at a time, smallest first. Open only as many as you need — the whole point of the puzzle is the part you work out yourself.

Hint 1

A trailing zero comes from a factor of 10, and 10 = 2 x 5.

Hint 2

There are far more 2s than 5s in the product, so every 5 finds a 2 to pair with. Count the 5s.

Show the answer Hide the answer

24 zeros.

How to get there

Each trailing zero needs a factor of 2 and a factor of 5. Factors of 2 are plentiful - every even number supplies at least one - so the number of zeros equals the number of 5s in the prime factorisation.

Multiples of 5 up to 100: there are 20 of them, each contributing at least one 5. But 25, 50, 75 and 100 are multiples of 25 and contribute a second 5 each: 4 more. Nothing up to 100 is a multiple of 125.

Total: 20 + 4 = 24 fives, so 24 trailing zeros. The general formula is floor(n/5) + floor(n/25) + floor(n/125) + ..., which for n = 1000 gives 200 + 40 + 8 + 1 = 249.

The technique worth keeping

A question about the shape of a huge number is a question about its prime factors. Find the scarcer of the two primes a feature requires and count its multiples, its square's multiples, and so on.