hdu1018 Big Number(阶乘数的位数)

Big NumberTime Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 30896Accepted Submission(s): 14313

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 ≤ 107on each line.

Output

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

Sample Input

21020

Sample Output

719

Source

Recommend

JGShining|We have carefully selected several similar problems for you:10131017107110081061

Statistic|Submit|Discuss|Note

敢想 敢写 就A了0.0

既然问某个数的阶乘有多少位

我们先拆开看看。如果问某个数n有几位。直接log10(n)就是结果了。既然问某个数的阶乘

也是一样的道理。log10(1*2*3*4*….*n),当然我们是不会让它乘这么多的 因为log10(a)+long10(b)=log10(a*b);

OK,看代码:

#include <stdio.h>#include <math.h>int main(){int ncase;scanf("%d",&ncase);while(ncase–){int n;double sum=0;scanf("%d",&n);for(int i=1;i<=n;i++)sum+=log10(i);printf("%d\n",(int)sum+1);}return 0;}

版权声明:本文为博主原创文章,未经博主允许不得转载。

,回避现实的人,未来将更不理想。

hdu1018 Big Number(阶乘数的位数)

相关文章:

你感兴趣的文章:

标签云: