![](https://i-blog.csdnimg.cn/blog_migrate/37ec10b8c41a8eccd9d22b5fcd375bd1.png)
n!的长度等于log10(n!)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
double ans = 1;
for(int i = 1; i <= n; i++) {
ans += log10(i);
}
cout << (int)ans << endl;
}
用斯特林公式求n!,然后log10(n!)即可
(如果怕n不够大下式不成立,可以当数小于10000时用for求阶层。不过51nod直接过了)
#include <bits/stdc++.h>
#define PI 3.1415926535898
#define e 2.718281828459
using namespace std;
int main() {
int T, n;
cin >> T;
while(T--) {
cin >> n;
double ans = log10(sqrt(2.0*PI*n)) + n*log10(n*1.0/e);// pow(n*1.0/e, n);
cout << (long long)ans + 1 << endl;
}
}