题目: 题解:
1)本题是求阶乘后的0,而0通过5 * 2=10求得,然而我们不必管2的个数,因为偶数就会产生2,所以我们只需要计算5的个数就好了。2)不过需要注意类似31!中的25=5 * 5有两个5,所以我们不仅需要统计当前小于n的数中有多少个5,还需要统计n的商中是否存在5。
代码如下:
class Solution {
public:
int trailingZeroes(int n
) {
int count
=0;
while(n
>=5)
{
count
+=n
/5;
n
/=5;
}
return count
;
}
};
转载请注明原文地址: https://mac.8miu.com/read-71377.html