HOJ 1296 Big Number

http://acm.hit.edu.cn/hoj/problem/view?id=1296

计算n!的位数

斯特灵公式:

n!≈sqrt(2*pi*n)*(n/e)^n

#include 
#include 

const double e = 2.7182818284590452354, pi = acos(-1);

int main()
{
    int n;
    int cases, dig;
    double fac;

    scanf("%d", &cases);
    while (cases--)
    {
        scanf("%d", &n);
        fac = log10( sqrt(2*pi*n)) + n*log10(n/e);
        dig = ceil(fac);
        printf("%d\n", dig);
    }

    return 0;
}


 

 

你可能感兴趣的:(HOJ)