末尾零的个数

经过学习(大雾), 我终于明白了, 原来可以用5的倍数的个数来计算末尾零的个数。

唉, 我果然够菜。

! 末尾有多少个 00 呢?

N! = 1 \times 2 \times \cdots \times NN!=1×2××N

代码框中的代码是一种实现,请分析并填写缺失的代码。


#include <iostream>
using namespace std;
int main() {
    int n, ans = 0;
    cin >> n;
    while (n) {
        ans += n/5, n /= 5;
    }
    cout << ans << endl;
    return 0;
}

N! = 1 \times 2 \times \cdots \times N


猜你喜欢

转载自blog.csdn.net/someone_and_anyone/article/details/79746614