基准时间限制: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
斯特林公式:
n!≈√(2πn)·(n/e)^n, 最后输出结果不要用%.0lf因为这样四舍五入,先转化为整数再输出
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#define maxn 50005
#define INF 1e18
#define MOD 10007
#define e 2.718281828459
using namespace std;
typedef long long ll;
int main(){
// freopen("in.txt", "r", stdin);
int t;
double n;
scanf("%d", &t);
while(t--){
scanf("%lf", &n);
printf("%I64d\n", (ll)(0.5 * log10(2*acos(-1)*n) + n * log10(n/e) + 1));
}
return 0;
}