# Shortest concise solution from geeksforgeeks

• ``````// http://www.geeksforgeeks.org/count-trailing-zeroes-factorial-number
// the result is equal to count total number of 5s in prime factors of n!
int trailingZeroes(int n) {
int ans = 0;
for (int i = 5; n >= i; i *= 5) {
ans += n / i;
}
return ans;
}``````

• a shorter one

``````int trailingZeroes(int n)  {
int c = 0;
for( ; n > 4; c += (n/=5) );
return c;
}``````

• Actually, my method is like this, but it's LTE!

• You can share your code, and find the LTE reason.

• ``````    int res = 0;
for(int m = 5; m <= n; m *= 5){
res += n / m;
}
return res;``````

• Last executed input: 2147483647

• ``````    int res = 0;
for(; n > 4; n /= 5){
res += n / 5;
}
return res;
``````

//When I modified the code like this, it passed the OJ, I think maybe we should not use extra varisbles.

• When n is really large, m might be overflow to a negative number. Therefore the loop will never exit. This is how you get your TLE

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.