why is this code rejected ,
#include <iostream>
using namespace std;
int main ()
{
unsigned int T, result, N, count , i;
cin >> T;
while (T--)
{
cin >> N;
result = count = 0;
for ( i = 5; i < N ; i = i * 5)//i (5 and its powers) is supposed to be less than N
{
result = result+N/i;
}
cout << result << endl;
}
return 0;
}
and this one is accepted :
#include <iostream>
using namespace std;
int main ()
{
unsigned int T, result, N, count , i;
cin >> T;
while (T--)
{
cin >> N;
result = count = 0;
for ( i = 5; N/i >= 1 ; i = i * 5)
{
result = result+N/i;
}
cout << result << endl;
}
return 0;
}
To me both conditions seem same.
In first code I am checking that the 5 and its powers are within the range.
In second code I am checking the division output of N! and 5 (and its powers).
why is my first code wrong ?