Given an integer n, return the number of trailing zeroes in n!.
Note: Your solution should be in logarithmic time complexity.
给一个整数n,返回n!后面0的个数。
n!的个数就是其中质因数2和5个数的个数,所以只要求出5的个数就是0的个数,所以代码如下:
class Solution {
public:
int trailingZeroes(int n) {
int i=0;
while(n)
{
i+=n/5;
n/=5;
}
return i;
}
};