标签:
N!阶乘是一个非常大的数,大家都知道计算公式是N!=N*(N-1)······*2*1.现在你的任务是计算出N!的位数有多少(十进制)?
3 1 3 32000
1 1 130271
斯特林公式:S=log10(2*PI*n)+n*log10(n/E)+1
PI=3.1415926
E=2.17828
长知识了 斯特林公式求数的阶乘长度
#include<stdio.h>
#include<string.h>
#include<math.h>
#define PI 3.1415926
#define E 2.71828
#define LL long long
LL len(int n)
{
LL s;
return s=log10(2*PI*n)/2+n*log10(n/E)+1;
}
int main()
{
int t,n,m,i,j;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
if(n<=3)
printf("1\n");
else
printf("%lld\n",len(n));
}
return 0;
}
标签:
原文地址:http://www.cnblogs.com/tonghao/p/4996100.html