How many trailing zeros does 250! have?
62. Each trailing zero needs a pair of 2 and 5, and 5s are scarcer, so count the 5s: 250/5 = 50, 250/25 = 10, 250/125 = 2 (take whole parts), total 62.
Explain it simply
A zero at the end of a number comes from a factor of 10, which is 2 x 5. In 250! there are plenty of even numbers, so 2s are never the problem. The 5s are the bottleneck, like the number of complete cricket teams being limited by how many wicketkeepers you have. So the question becomes: how many 5s hide inside 1 x 2 x ... x 250?
Example
Question: Find the number of trailing zeros in 250!.
- Multiples of 5 up to 250: 250 / 5 = 50. Each gives at least one 5.
- Multiples of 25 give an extra 5: 250 / 25 = 10.
- Multiples of 125 give one more: 250 / 125 = 2.
- Multiples of 625: none.
- Total = 50 + 10 + 2 = 62.
let n = 250, zeros = 0;
for (let p = 5; p <= n; p *= 5) zeros += Math.floor(n / p);
console.log(zeros); // Output: 62What to say in the interview
"Trailing zeros equal the number of 10s, and since 2s are more common than 5s I only count 5s. I divide by 5, 25, 125 and so on, keeping whole parts, and add. For 250 that is 50 + 10 + 2 = 62."
Common mistakes
- Stopping after dividing by 5 and answering 50; 25 contains two 5s, 125 contains three.
- Counting 2s instead of 5s.