#K58887. Trailing Zeros in Factorial
Trailing Zeros in Factorial
Trailing Zeros in Factorial
Given a non-negative integer n, the task is to compute the number of trailing zeros in n! (n factorial). Trailing zeros are caused by the factors 10 in the factorial, and since 10 is the product of 2 and 5, and there are usually more factors of 2 than 5, the number of trailing zeros is determined by the number of times 5 is a factor in the numbers from 1 to n.
The mathematical formula for this is:
\( Z(n) = \sum_{i=1}^{\infty} \left\lfloor \frac{n}{5^i} \right\rfloor \)
where \( \lfloor \cdot \rfloor \) denotes the floor function. The sum terminates when \(5^i > n\).
inputFormat
The input consists of a single integer n (\(0 \leq n \leq 10^9\)).
outputFormat
Output a single integer representing the number of trailing zeros in n!.
## sample0
0