Problem code: FCTRL Factorial

why is it showing wrong answer?

#include
using namespace std;
int main()
{
int count,div,i,t;
long long int n;
cin>>t;
while(t>0)
{

div=5;
count=0;
cin>>n;
for(i=1;i<div;i++)
{
	count+=n/div;
	div=div*5;
}
cout<<count<<endl;;
t--;
}

}

your approach is correct…But the data type of div should be long long int…as the value of div increases exponentially it causes an overflow in case of int datatype before the actual limit is reached…
you can have a look at the modified program here

1 Like
//