In this article, We will see another problem of CSES which is ” Trailing Zeros CSES Solution “. In this problem, we have to find the number of trailing zeros after calculating n!
Let’s see the problem statement.
Problem statement:
Your task is to calculate the number of trailing zeros in the factorial n!.
For example, 20!=2432902008176640000 and it has 44 trailing zeros.
Input
The only input line has an integer n.
Output
Print the number of trailing zeros in n!.
Constraints
- 1≤n≤1091≤n≤109
Example
Input:20
Output:4
//Trailing Zeros CSES Solution import java.util.*; import java.io.*; public class TrailZeros { static long Trail(long num) { long ans=0; for (long i = 5; i <= num; i*=5) ans += num / i; return ans; } public static void main(String args[]) { Scanner sc=new Scanner(System.in); long n=sc.nextLong(); System.out.println(Trail(n)); } } //Trailing Zeros CSES Solution