## Big Number

Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 951 Accepted Submission(s): 640

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 ≤ 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

21020

Sample Output

719

Source

Asia 2002, Dhaka (Bengal)

Recommend

JGShining

这道题对于C/C++的写法来说，n太大阶乘出来的结果已经超出了所能表示的整数的范围。这时候主要有以下两种思考：

1）用科学计数法a*10^n来表示N!。那么这时候n+1就是N！的位数。(其实这种想法就是直接暴力，只不过是在暴力之前做了以下处理。因为N！的范围太大，C/C++的整数范围内存不下)

N的阶乖的位数等于LOG10（N！）＝LOG10（1）＋.....LOG10（N）；

2）用斯特林公式获得N！的近似值。然后计算这个近似值的位数。

``````/*
* c.cpp
*
*  Created on: 2015年2月3日
*/

#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

int main(){
int t;
scanf("%d",&t);
while(t--){
int n;
scanf("%d",&n);
int i;
double ans = 0;
for(i = 1 ; i <= n ; ++i){
ans += log10(i);
}

printf("%d\n",(int)ceil(ans));//ceil()函数用于向上取整.
}

return 0;
}``````