1320. Zeros At the End of a Factorial
Print how many zeros the number n! ends with.
Computing n! is impossible here. At n = 10^9 the number has hundreds of
millions of digits, so the answer has to come from the factors alone.
A trailing zero is a factor of 10, and 10 is 2 times 5. Among 1..n the factor
2 appears far more often than 5, so the number of fives is what limits the count.
Count them, remembering that 25 contributes two fives, 125 contributes three, and so on:
n/5 + n/25 + n/125 + n/625 + ...
using integer division and stopping when the power passes n.
Only counting n / 5 is the usual wrong answer, and it goes wrong first at
n = 25, which has 6 zeros rather than 5. That case is in the tests.
Watch the power itself: at n = 10^9 a 32-bit accumulator for 5^k overflows
before the loop ends, which turns the condition into a wrap and loops forever.
Constraints - `0 ≤ n ≤ 1000000000`
Input
One line containing the integer n.
Output
Print how many zeros n! ends with.
Hints
Four rungs, in order. The last two open once you have submitted an attempt. A wrong one counts.