题目:
Given an integer n, return the number of trailing zeroes in n!.
解答:
首先要明白,产生0的只有2和5相乘,其次所有的约数中2的数目肯定比5多,所以直接看1~n这n个数中一共能分解出多少个5就是最终n!中的0的个数
所以代码就很简单了
class Solution {
public:
int trailingZeroes(int n) {
int res = 0;
while(n >= 5)
{
res += n / 5;
n = n / 5;
}
return res;
}
};