求 n! 末尾零的个数,在编程之美上看过,其实也不难:求因子2和5的个数取最小值,因为5出现的频率远低于2。
# include <stdio.h> int solve(int n); int main() { int T, n; scanf("%d", &T); while (T--) { scanf("%d", &n); printf("%d\n", solve(n)); } return 0; } int solve(int n) { int t; t = 0; while (n>0) {n /= 5; t += n;} return t; }