Files
python/TangDou/LuoGuBook/POJ1423_2.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

30 lines
676 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
/*
思想:底数相同的两个数相乘底数不变,指数相加。
通过log10(x)得到指数,依次相加即可,即可以得到阶乘的位数
*/
const int N = 10000010;
int a[N];
int main() {
//预处理出阶乘的位数
double x = 0;
for (int i = 1; i < N; i++) {
x += log10((double)i); // POJ对于log10(i)会报编译错误需要转为double
a[i] = x + 1;
}
// T次询问
int T;
scanf("%d", &T);
while (T--) {
int n;
scanf("%d", &n);
printf("%d\n", a[n]);
}
return 0;
}