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
题目大意:给定数n,求n!的位数。
打开传送门
附ac代码
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
const double pi=acos(double(-1));
const double e=exp(double(1));
int n,ans;
int digit(int x)
{
if(x==1)
return 1;
return floor(log10(sqrt(2*pi*x))+x*log10(x/e))+1;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
printf("%d\n",digit(n));
}
return 0;
}
本文介绍了一种计算给定整数阶乘位数的方法,并提供了一段AC代码实现。通过输入一个整数n,程序能够输出n!的位数。
740

被折叠的 条评论
为什么被折叠?



