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

Factorial- FCTL. my code gives TLE. bt it runs fine on ideone for the given sample input. Can anyone help me in optimising the code.

$
0
0

I checked the code in my computer also for different inputs.

 enter code here
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<map>

using namespace std;
int main()
{
    unsigned long test;
    scanf("%lu",&test);
    unsigned long clll[test];
    unsigned long check;
    map<int,long> m;
    for(unsigned long i=0;i<test;i++)
        {
            unsigned long Num;
            scanf("%lu",&Num);
            m[2]=0;
            m[5]=0;
            for(unsigned long j=1;j<=Num;j++)
            {
                check=j;
                while((check%2==0)&&(check>0))
                {
                    m[2]++;
                    check/=2;
                }
                while((check%5==0)&&(check>0))
                {
                    m[5]++;
                    check/=5;
                }
            }
        clll[i]=m[2]>m[5]?m[5]:m[2];
    }
      for(int ni=0;ni<test;ni++)
        printf("%lu\n",clll[ni]);
      return 0;
}

Viewing all articles
Browse latest Browse all 39796


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