 # problem code FCTRL -- my code giving time limit exceeded error

my code ( http://www.codechef.com/viewsolution/4402646 ) for the problem - factorial - is giving time limit exceeded error, please suggest any way to modify my code to remove the error

Your code is giving tle as you are trying to compute the factorial first , there is no need to compute the factorial .

Also note that factorial grows very rapidly , the factorial of 100 factorial is 157 digits long , so you can`t calculate the factorial using int and even long long int .

you can directly compute the number of zeros without computing the actual factorial .

Use this link to see how it can be done , Here is my solution . If you need any help , please comment , also if you find my answer useful please upvote and accept it as right answer .

Happy Coding !!!

before seeing ur answer I searched about the logic to find trailing zeroes in factorial and I found the logic same which u used in ur solution and applied the logic in my code to modify it but still its giving TLE error … here is my solution link - http://www.codechef.com/viewsolution/4404655 - plzz check it and suggest how can i modify it to remove tle error

In your code there are two problems :

1. You are taking long long input by using the wrong identifier , correct method should be scanf("%llu",&n); instead of scanf("%d",&n); .
2. Everytime k should be multiplied to 5 instead of j , if you multiply it by j power will grow as 5,10,30,120 which is wrong .

After changing both the errors , here is your accepted code .

If you need any help , please comment , also if you find my answer useful please upvote and accept it as right answer .

Happy Coding !!!

//