Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 39796

FCTRL - TLE

$
0
0

Time limit getting exceeded and also the program not seeming to work for N>=60 in FCTRL question in easy practice problems section. What is wrong with my code?

I ran it on gdb and found that as your N goes above 60 then t and p become very large and reach the max value they can hold and hence program isn't working for N>60. I saw the solution in the submissions column of the problem but i am not able to comprehend it. Pls explain what the mistake is in my program and what is the best way to implement it . thanks ...

#include<stdio.h>

int z(unsigned long);


int main(void)
{
 unsigned long t=0,i;
 scanf("%lu",&t);

 for(i=0;i<t;i++)
  {
   unsigned long n;
   scanf("%lu",&n);
   if(n>=1&&n<=1000000000)
   {
   int ctr=z(n);
   printf("%d\n",ctr);
   }
   else
    return 0;
  }
  return 0;
}
int z(unsigned long n)
{
 int tz=0;
 unsigned long long t,p=1;
 t=n;
 while(1)
  {
   printf("n=%lu t=%llu tz=%d p=%llu\n ",n,t,tz,p);
   n--;
   p=t*n;
   while(p%10==0)
    {
     p/=10;
     tz++;
    }
    t=p;
    if(n<=1)
     break;
  }
return tz;
}

Viewing all articles
Browse latest Browse all 39796

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>