FTCRL: Need number of trailing zeroes in a factorial

here’s my solution in c. it works fine on dev c++ but the judge only displays wrong answer. is there any logical error?

#include<stdio.h>
#include<math.h>
int main()
{
    long int n[100000],T,i,ans[100000],j,k,m;
    scanf("%ld",&T);
    for(i=0;i<T;i++)
    {
        scanf("%ld",&n[i]);
    }
    for(k=0;k<T;k++)
    for(j=0;j<10;j++)
    {
        ans[k]=ans[k]+n[k]/pow(5,(j+1));
    }
    for(m=0;m<T;m++)
    printf("%ld \n",ans[m]);
    return 0;
}

N can be up to 1.000.000.000 (according to the problem statement). your loop on j should check values until j = 13 (5^13 = 1.220.703.125), not j = 10 (5^10 = 9.765.625). it seems you forgot some zeroes. :slight_smile:

2 Likes

oh yeah got it!! thanks cyberax

//