Last active
August 20, 2016 13:04
-
-
Save rishi93/6b335d13327c061eb85a to your computer and use it in GitHub Desktop.
Factorial Trailing Zeros - FCTRL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int noOfTrailingZeros(int n){ | |
int count = 0; | |
int divisor = 5; | |
//First, we count the number of multiples of 5 in the expansion of n! | |
//Then we count the number of multiples of 25, and then 125, and so on.. | |
while(divisor <= n){ | |
count += n/divisor; | |
divisor *= 5; | |
} | |
return count; | |
} | |
int main(){ | |
//For Fast IO | |
ios_base::sync_with_stdio(false); | |
cin.tie(NULL); | |
int t,n; | |
cin>>t; | |
for(int testcase=0; testcase<t; testcase++){ | |
cin>>n; | |
cout<<noOfTrailingZeros(n)<<"\n"; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment