1018

1 /*Problem Description
2 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.
3
4
5
6 Input
7 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.
8
9
10
11 Output
12 The output contains the number of digits in the factorial of the integers appearing in the input.
13
14
15
16 Sample Input
17 2
18 10
19 20
20
21
22 Sample Output
23 7
24 19
25
26 输入个大数
27 输出该数的阶乘的位数
28
29 log10(n!) = log10(n*n-1*n-2......*2*1) = log10(n) + log10(n-1) + log10(n-2) + ...... + log10(2) + log10(1)
30
31 Accepted 1018 968MS 352K
32  */
33
34 #include<iostream>
35 #include<cmath>
36 using namespace std;
37 int main()
38 {
39 int n,m;
40 double cnt;
41 cin>>n;
42 while(n--)
43 {
44 cnt = 0.0;
45 cin>>m;
46 for(int i=1;i <=m ; ++i)
47 cnt += log10(i*1.0);
48 int res = (int)cnt+1;
49 cout << res << endl;
50 }
51 return 0;
52 }
53

 

posted @ 2010-04-15 23:13  にんじゃ  阅读(276)  评论(0)    收藏  举报