标签:while rmi stdio.h 数值 span include others clu contains
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 38886 Accepted Submission(s):
18889
//求一个超大数阶乘的位数
//所谓n!的十进制位数,就是 log(n)+1, 根据数学公式有:n!=1*2*3*.....*n;
//lg(n!)=lg(2)+......lg(n);
//则位数 = log(n)+1;
#include<stdio.h>
#include<math.h>
double f(int n)
{
double cnt=0;
for(double i=2;i<=n;i++) // i也要为double型,否则会出现歧义 !
{
cnt += log10(i);
}
return cnt;
}
int main()
{
int cas,n;
scanf("%d",&cas);
while(cas--)
{
scanf("%d",&n);
printf("%d\n",(int)f(n) + 1);
}
return 0;
}
标签:while rmi stdio.h 数值 span include others clu contains
原文地址:http://www.cnblogs.com/shirley-0021/p/shirley-21.html