hdoj 1018 Big Number

http://acm.hdu.edu.cn/showproblem.php?pid=1018
题目意思是求N!有几位
Stirling公式:
log10(n!)=log10(sqrt(2∗pi∗n))+n∗log10(n/e)
所以、、数论题就是会的人秒出,不会的人死都写不出

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;
int n,a[1010];
int digit_stirling(int n)
{
    double PI=acos(double(-1));// PI的值=反余弦函数 -1.0为Pi, 1为0。
    double e=exp(double(1));//e的值
    return floor(log10(sqrt(2*PI*n))+n*log10(n/e))+1;//斯特林公式 
}
int main()
{
    int n,T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&n);
        printf("%d\n",digit_stirling(n));
    }
    return 0;
} 

猜你喜欢

转载自blog.csdn.net/sdxtcqs/article/details/78760525