# How To calculate Trailing Zeros in N factorail | count Number of trailing zero in N! CSES problem solution

## How To calculate Trailing Zeros in N factorail | count Number of trailing zero in N! CSES problem solution -

This problem is taken form CSES Introductory Problem set. Here You have to count Number of Trailing zero in N!.

## Problem Statement-

Your task is to calculate the number of Trailing Zeros in the factorial  $n!$.

For example, $20!=2432902008176640000$ and it has $4$ trailing zeros.

Input

The only input line has an integer $n$.

Output

Print the number of trailing zeros in $n!$.

Constraints
• $1\le n\le {10}^{9}$
Example

Input:
20

Output:
4

## Solution-

Recommended practice yourself Before jumping to solution.

So here is A hidden logic behind solving this problem. Think Condition when zero comes as trailing zero when we multiply two numbers.
Zero comes at the end when a number multiplied by 10. So we have to find How many times 10 can be formed in N!.
since 10 is multiple is 2 and 5 so we can get 10 only when 2 and 5 are multiplied so it is better to find how many times we 5 occur in N!.
So For finding number of 5 in N! we have a formula.

Join me on Telegram-https://t.me/competitiveProgrammingDiscussion

Trailing 0s in n! = Count of 5s in prime factors of n!                  = floor(n/5) + floor(n/25) + floor(n/125) + ....
So this is how we can calculate the number of trailing Zeros in N!.

Code Solution of this Problem-

This post first appeared on Technical Keeda, please read the originial post: here

# Share the post

How To calculate Trailing Zeros in N factorail | count Number of trailing zero in N! CSES problem solution

×

# Subscribe to Technical Keeda

Get updates delivered right to your inbox!

×