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
求一个数阶乘的位数
首先会想到把这玩意弄成log的情况
讲道理的话会想到log里边相乘的玩意在外边就是加
为了让他精确点
把不到10的玩意在外边乘完了
超过十给他一波log
一定要用double记录
上代码
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n;
cin >> n;
while (n--)
{
int h;
cin >> h;
double tem = 0;
int y=1;
for (int a = 2;a <= h;a++)
{
y = y*a;
if (y < 10)continue;
else
{
tem = tem + log10(y*1.0);
y = 1;
}
}
tem = tem + 1;
cout << (int)tem << endl;
}
return 0;
}