Given an integer n, return the number of trailing zeroes in n!.
Note: Your solution should be in logarithmic time complexity.
Credits:
Special thanks to @ts for adding this problem and creating all test cases.
给出n,求n的阶乘的尾部0的个数。转换成统计5因子的个数。
代码:
class Solution {
public:
int trailingZeroes(int n) {
int res = 0;
long long m = 5;
while(m <= n)
{
res += (n / m);
m *= 5;
}
return res;
}
};