unsigned int count(unsigned int n) { unsigned int cnt = 0; unsigned int i, j; for (i = 1; i <= n; i++) { j = i; while (j % 5 == 0) { cnt++; j /= 5; } } return cnt; }
或
unsigned int count(unsigned int n) { unsigned int cnt = 0; while (n) { cnt += n / 5; n /= 5; } return cnt; }
本质是求有几个5