数学 | 阶乘后的零
统计阶乘之后的结果有多少个0,就是统计阶乘有多少个5
n! = N*(N-1)*(N-2)*(N-3)......
1...5....2*5 .....4*5 .....5*5.....5*5.......2*5*5......5*5*5......n
count = n/5+n/25+n/125+.....
public int trailingZeroes(int n) {
int count = 0;
for (int i = 1; i <= n; i++) {
int N = i;
while (N > 0) {
if (N % 5 == 0) {
count++;
N /= 5;
} else {
break;
}
}
}
return count;
}