#K54362. Count Trailing Zeros in Factorials
Count Trailing Zeros in Factorials
Count Trailing Zeros in Factorials
Given a positive integer n, compute the number of trailing zeros in n! (n factorial). The number of trailing zeros in n! is determined by the number of times 5 is a factor in the numbers from 1 to n. This can be computed by the formula:
$$ Z(n) = \sum_{i=1}^{\infty} \left\lfloor \frac{n}{5^i} \right\rfloor $$
The input consists of several non-negative integers, each provided on a separate line, terminated by -1 which should not be processed.
inputFormat
Input is read from standard input (stdin). It contains a sequence of non-negative integers, one per line. The sequence is terminated by the integer -1, which signals the end of input.
outputFormat
For each input integer (except the terminating -1), output on a separate line a single integer representing the number of trailing zeros in the factorial of the given number.
## sample5
10
25
-1
1
2
6
</p>