Factorials problem spoj Solution

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

Popular posts from this blog

Small Factorials Spoj Solution(using python)