A - 结果填空:阶乘位数 计蒜客 - A2221

蒜头君对阶乘产生了兴趣,他列出了前 10 10 10 个正整数的阶乘以及对应位数的表:

n n n n ! n! n! 位数
1 1 1
2 2 1
3 6 1
4 24 2
5 120 3
6 720 3
7 5040 4
8 40320 5
9 362880 6
10 3628800 7
对于蒜头君来说,再往后就很难计算了。他试图寻找阶乘位数的规律,但是失败了。现在请你帮他计算出第一个正整数的阶乘位数大于等于 10000 10000 10000 的数是多少,即求最小的正整数 n n n 满足 n ! n! n! 的位数大于等于 10000 10000 10000

Sample Input

Sample Output

#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
    
    
    double s=0;
    for(int i=1;; i++)
    {
    
    
        s+=log10(i);//斯特林公式判断阶乘位数核心代码
        if(int (s+1)>=10000)
        {
    
    
            cout<<i<<endl;
            break;
        }
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/JdiLfc/article/details/109118602
今日推荐