This is my solution for the Factorial problem under the Practice < Easy section.

I’m getting wrong answer when i submit.

#include<stdio.h>

#include<math.h>

long int fact (long int);

int main ()

{

long int t;

long int i;

scanf("%ld",&t);

if(t>100000);

else{

long int arr[t];

for(i=0;i<t;i++)

scanf("%ld",&arr[i]);

for(i=0;i<t;i++)

{if(arr[i]>1000000000||arr[i]<1);

else

printf("%ld\n",fact(arr[i]));

}}

return 0;

}

long int fact (long int x)

{

long int i=1,term;

long int sum=0;

while(term>=1)

{ term=x/pow(5,i);

sum=sum+term;

```
i++;
}
return sum;
```

}

Your code gives Wrong Output for:

Input
1000000000
Expected Output:
249999998
Your Output:
249999997

How should I fix this ?

And how did you figure this thing out that I’m getting wrong output for this specific input ?

(sorry I’m new here)

I have tested some test cases against your code and my AC’ed code, and so i got the test case for which your code failed

See this was my logic:

val =((num/5) + (num/25) + (num/125) + (num/625) + (num/3125) + (num/15625) + (num/78125) + (num/390625) + (num/1953125) + (num/9765625) + (num/48828125) + (num/244140625) + (num/1220703125) );

I computed all 5^i according to constraints and solved the problem.