For this problem, when we use the languages like c++ , c it is going to show due to time or time limit exceded ,for getting solution i used python . t=int(input()) while(t): n=int(input()) fact=1 for i in range(1,n+1): fact=fact*i print(fact) t=t-1 If you have any doubts comment below 👇
In order to find factorial of n and number zeros at the end of factorial decimal, i simply find prime factors (5) ,and find the count then the count is our required answer. #include <iostream> using namespace std; typedef long long l; int zero(l ); int main() { l t; cin>>t; while(t--){ l n; cin>>n; cout<<zero(n)<<endl; } return 0; } int zero(l n){ l c=0; if(n<0) return 0; for(l i=5;n/i>=1;i=i*5){ c+=n/i; } return c; }
Comments
Post a Comment