The solution to FACTORIAL problem (Problem Code: FCTRL) works perfectly fine in my laptop but is giving a Wrong Answer in SPOJ submission.
Kindly look at my code and let me know if something is incorrect.
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int trailingzeros(int num)
{
int z=0;
int counter = 1;
int factor = 5;
while(num > factor)
{
z = z + num/factor;
factor = factor * 5;
}
return z;
}
int main()
{
int z = 0;
int *num, c=0, i=0;
string str;
//cout<<"Input: "<<endl;
getline(cin, str);
c = atoi(str.c_str());
num = new int[c];
while(i<c)
{
getline(cin, str);
num[i] = atoi(str.c_str());
i++;
}
i=0;
cout<<endl;
//cout<<"Output: "<<endl;
while(i<c)
{
z=trailingzeros(num[i]);
cout<<z<<endl;
i++;
}
//cin.get();
return 0;
}
Sample Input:
6
3
60
100
1024
23456
8735373
Sample Output:
0
14
24
253
5861
2183837