#K64662. Trailing Zeros of Factorial

    ID: 32026 Type: Default 1000ms 256MiB

Trailing Zeros of Factorial

Trailing Zeros of Factorial

Given a non-negative integer \( n \), compute the number of trailing zeros in \( n! \) (the factorial of \( n \)).

The trailing zeros of a factorial are caused by the factors of 10 in the product, and since \( 10 = 2 \times 5 \), the number of zeros is determined by the number of times 5 is a factor in the factorial (because there are usually more factors of 2 than 5).

The answer can be computed using the formula:

\( Z(n) = \sum_{k=1}^{\infty} \left\lfloor \frac{n}{5^k} \right\rfloor \)

This sum terminates when \( 5^k > n \).

inputFormat

The input consists of a single non-negative integer \( n \) provided via stdin.

outputFormat

Output a single integer representing the number of trailing zeros in \( n! \) to stdout.

## sample
5
1

</p>