1. 阶乘后的0
// 求解 n! 质因子10的个数,而10 = 2 * 5。
// 因此转换成求n!中质因子 2 的个数和质因子 5 的个数的较小值。
// 最终求n!中质因子5的个数
int trailingZeroes(int n) { // 时间复杂度O(logn)
int cnt = 0;
while (n) {
n /= 5;
cnt += n;
}
return cnt;
}
int trailingZeroes(int n) { // 时间复杂度O(n)
int cnt = 0;
for (int i = 1; i <= n; i++) {
int num = i;
while (num % 5 == 0) {
cnt++;
num /= 5;
}
}
return cnt;
}