大数阶乘的位数(C++)
1 //斯特林公式: 2 #include<iostream> 3 #include<cmath> 4 using namespace std; 5 int n; 6 #define e 2.7182818284590452354 7 #define PI 3.141592653589793239 8 int main() 9 { 10 int t,des; 11 double i,sum; 12 scanf("%d",&t ); 13 while(t-- ) 14 { 15 scanf("%d",&n); 16 if(n<100000) 17 { 18 for(sum=0,i=1;i<=n;i++) 19 { 20 sum+=log10(i); 21 } 22 } 23 else 24 { 25 sum=log10(sqrt(2*PI*n))+n*log10(n/e); 26 } 27 des=(int)sum; 28 if(des<=sum)des++; 29 printf("%d\n",des); 30 } 31 return 0; 32 }