0
点赞
收藏
分享

微信扫一扫

HDU 1018 Big Number N!的位数


Big Number


Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 25034    Accepted Submission(s): 11375

Problem Description


In many applications very large integers numbers are required. Some of these applications are using keys for secure transmission of data, encryption, etc. In this problem you are given a number, you have to determine the number of digits in the factorial of the number.


Input


Input consists of several lines of integer numbers. The first line contains an integer n, which is the number of cases to be tested, followed by n lines, one integer 1 ≤ n ≤ 10 7 on each line.


Output


The output contains the number of digits in the factorial of the integers appearing in the input.


Sample Input


2 10 20


Sample Output


7 19


阶乘


10^x=N!  x=log10N!


/*
1018 Big Number
求N!的位数

n!=1*2*3...*n
log10(n!)=log10(1*2*3...*n) =log10(1)+log10(2)+...log10(n)
所以位数就是log10(n!)

看网上还有 斯特林数
log10(n!)=1.0/2*log10(2*pi*n)+n*log10(n/e)


本地正确 提交OJ错误
0_0_10911911_23158.cpp
0_0_10911911_23158.cpp(26) : error C2668: “log10” : 对重载函数的调用不明确
\include\math.h(614): 可能是“long double log10(long double)”
\include\math.h(566): 或 “float log10(float)”
\include\math.h(194): 或 “double log10(double)”
试图匹配参数列表“(int)”时

log10(i)===》log10(i+0.0);
*/
#include<iostream>
#include<cmath>
using namespace std;
int main(){

int i,n,t;
double sum;
cin>>t;
while(t--)
{
cin>>n;
sum=1; //至少一位 也相当于进位取整
//log(10)120=2.x int之后为2 加上1为3
for(i=1;i<=n;i++)
sum+=log10(i+0.0);
printf("%d\n",(int)sum);
}

return 0;
}

举报

相关推荐

0 条评论