M

来源:互联网 发布:猎场小说剧情介绍 知乎 编辑:程序博客网 时间:2024/04/29 10:40

Big Number

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


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 ≤ 107 on 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
Asia 2002, Dhaka (Bengal)
 

Recommend
JGShining
(题目来源于http://acm.hdu.edu.cn/showproblem.php?pid=1018)

解题思路:
运用取对数思想:
举一个简单的例子,100有多少位,3位。log10(100)=2;2+1=3;
log10(976)=2.9894;加1后等于3.984,取int后为3;

需要有的知识:
1、log和log10在头文件<math.h>,在c++中也可以用<cmath>
2、double log( double x );(以e为底)
     double log10( double x );

扩展知识:
1、如何表示以其他数为底的数字呢,例如log3(x)
运用换底公式即可,log3(x)=ln(x)/ln(3)或者log(x)/log(3);

代码展示:
#include<iostream>#include<cmath>using namespace std;int main(){int n=0;while(cin>>n){while(n--){int m=0;double sum=0;cin>>m;for(;m>=2;m--){sum=sum+log10(m);}cout<<(int)sum+1<<endl;}}}