基准时间限制:1 秒 空间限制:131072 KB 分值: 0
难度:基础题
输入N求N的阶乘的10进制表示的长度。例如6! = 720,长度为3。
Input
第1行:一个数T,表示后面用作输入测试的数的数量。(1 <= T <= 1000) 第2 - T + 1行:每行1个数N。(1 <= N <= 10^9)
Output
共T行,输出对应的阶乘的长度。
Input示例
3 4 5 6
Output示例
2 3 3
求阶乘的长度本来可以用遍历每个数求log10(x),再加一,这个题里面数太多,循环一遍太费时间。
还有一个方法就是斯特林近似。
#include<map>
#include<stack>
#include<queue>
#include<math.h>
#include<vector>
#include<string>
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#define maxn 2000005
#define inf 0x3f3f3f
#define ll unsigned long long
#define mod 1000000000
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
const double e = 2.718281828459;
const double pi = 3.1415926;
int main()
{
ll t;
cin>>t;
while(t--){
ll v,f;
cin>>v;
f=1+0.5*log10(2*pi*v)+v*log10(v/e);
cout<<f<<endl;
}
}