10^7! problem – stirling’s formula

斯特林公式:lnξ = ξlnξ-ξ+0.5ln(2ξ*PI)
ξ的阶乘的位数等于:log10(ξ!)取整后加1,log10(ξ!) = lnξ! / ln(10)。

#include<stdio.h>

#include<math.h>

#define PI 3.14159265

#define N 10000000

int main(){

    int len;

    len=ceil((Nlog(N)-N+log(2N*PI)/2)/log(10));

    //ceil求上界,即不小于某值的最小整数

    //log在c语言里面是自然对数

    printf(“%dn”,len);

    return 0;

}

//len=65657060