hdu 1018

Big Number

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


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
2 10 20
 

Sample Output
7 19
 

Source
 1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
4 #include <math.h>
5 #define PI 3.14159265 // acos(-1)
6 /*
7 *求N!斯特林公式
8 * In n! = n In n - N + 1 / 2 * In( 2 * pi * n);
9 * 维基百科:
10 * http://zh.wikipedia.org/wiki/%E6%96%AF%E7%89%B9%E6%9E%97%E5%85%AC%E5%BC%8F
11 */
12
13 void solve_digit(int N)
14 {
15 int i, j, t;
16
17 t = (N * log (N) - N + 0.5 * log ( 2 * PI * N)) / log(10); //log是以e为底的
18 printf("%d\n", t + 1);
19 }
20
21 int main( )
22 {
23 int N, t;
24 scanf("%d", &N);
25 while (N--) {
26 scanf("%d", &t);
27 solve_digit(t);
28 }
29 return 0;
30 }
31
32

posted on 2011-08-26 00:33  more think, more gains  阅读(169)  评论(0编辑  收藏  举报

导航