POJ1423-阶乘的位数-Big Number

转载请注明出处:http://www.cnblogs.com/zhishoumuguinian/p/8425095.html
 
Big Number
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 28698   Accepted: 9127

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 <= m <= 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

 

思路:这是数论的题,需要用到的有两个公式:

1.求x的长度   log10(x);2.

 

 1 #include<iostream>
 2 #include<math.h>
 3 using namespace std;
 4 #define PI 3.1415926535897932384626433832795
 5 #define e  2.7182818284590452353602874713527
 6 int main()
 7 {
 8     int k;
 9     cin>>k;
10     while(k--)
11     {
12 
13     int n;
14     cin>>n;
15     cout<<(int)(log10(sqrt(2*PI*n))+n*log10(n/e))+1<<endl;
16 }}

 

 

 


posted @ 2018-02-07 09:15  nefuer  阅读(198)  评论(0)    收藏  举报