阶乘大全

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;
}

其实就是求5的个数

n的结果有几位

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    double ans = 0;
    cin >> n;
    for(int i=1;i<=n;i++)
    {
        ans+=log10(i);
    }
    cout << (int)ans+1 << endl;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_36979930/article/details/79702278