n!的位数=log10(1)+...+log(n);
n!=sqrt(2*π*n)*(n/e)^n;
代码如下:
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int m,n;
cin>>m;
for(int i=0;i<m;i++)
{
cin>>n;
double sum=0.5*log10(2*3.1415927*n)+n*log10(n/2.718281828459);
cout<<(int)sum+1<<endl;
}
return 0;
}