poj1423 Big Number

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

AC Code

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <limits.h>
#include <queue>
#define inf 0x3f3f3f3f
#define MAXM 200005

using namespace std;

const double pi=3.141592653589793239,e=2.7182818284590452354;

double stirling(long n)
{
	return 0.5*log10(2*pi*n)+n*log10(n/e);
}


int main(int argc, char** argv) {
	int t;
	cin>>t;
	while(t--){
		long n;
		cin>>n;
		cout<<(int)stirling(n)+1<<endl;
	}
	return 0;
}





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章