这种题目考的是数学功底啊,用脚趾都能想到,任何一个数的长度等于它对10求对数加1;
而log10(n!)=log10(1*2*3*4*5********n)=log10(1)+log10(2)+............+log10(n);
#include<map> #include<set> #include<queue> #include<cmath> #include<vector> #include<cstdio> #include<string> #include<cstring> #include<cstdlib> #include<iostream> #include<algorithm> #define inf 0x0f0f0f0f using namespace std; const double pi=acos(-1.0); const double eps=1e-8; typedef pair<int,int>pii; double get_len(int n) { double sum=0.0; for (int i=1;i<=n;i++) { sum+=double(log10(i+0.0)); } return sum; } int main() { //freopen("in.txt","r",stdin); int t,n; scanf("%d",&t); while (t--) { scanf("%d",&n); int len=int(get_len(n))+1; printf("%d ",len); } //fclose(stdin); return 0; }