http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1130

对于这类问题:斯特林近似公式:

 
 
百度百科的证明:http://baike.baidu.com/link?url=SIkpaHdNUtWRJay6tu8G_-1nmw6_XYXXHwSJATOc3cHGRv1lK1SpM-Xdt6HCHFvJKyEe-Zf8blVm8KA9QyfIEK
 
 
然后就是这个代码的化简:

#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

#define N 211111
#define pi acos(-1.0)

int main()
{
    int T;
    scanf("%d",&T);
    while (T--)
    {
        int n;
        scanf("%d",&n);
        if (n==1)
        {
            printf("1\n");
            continue;
        }
        double ans=log10(sqrt(pi*2*n));
        ans+=1.0*n*log10(1.0*exp(-1.0)*n);

ll an=ans+0.999999;
        printf("%lld\n",an);
    }

return 0;
}