题目:
算法思想:
阶乘展开以后可以发现,最终结果的0,都是由5*2所产生,所以只需要统计,一共有多少个5即可。
代码:
int count = 0;
public int trailingZeroes(int n) {
if (n == 0) {
return 0;
}
for (int i = n; i >= 1 ; i--) {
int j = i;
while(j % 5 == 0) {
count++;
j = j / 5;
}
}
return count;
}