题目链接:点击打开链接
斯特林数:点击打开链接
题意是计算n! 的位数
即ans = log10(n!) = log10(sqrt(2πn)) + n*log10(n/e)
#include <stdio.h> #include <iostream> #include <algorithm> #include <sstream> #include <stdlib.h> #include <string.h> #include <limits.h> #include <vector> #include <string> #include <time.h> #include <math.h> #include <iomanip> #include <queue> #include <stack> #include <set> #include <map> const int inf = 1e8; const double eps = 1e-8; const double pi = acos(-1.0); template <class T> inline bool rd(T &ret) { char c; int sgn; if(c=getchar(),c==EOF) return 0; while(c!='-'&&(c<'0'||c>'9')) c=getchar(); sgn=(c=='-')?-1:1; ret=(c=='-')?0:(c-'0'); while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0'); ret*=sgn; return 1; } template <class T> inline void pt(T x) { if (x <0) { putchar('-');x = -x; } if(x>9) pt(x/10); putchar(x%10+'0'); } using namespace std; typedef long long ll; typedef pair<int,int> pii; const double Pi = acos(-1.); const double e = 2.718281828459045; double n; int main(){ int T; rd(T);while(T--){ cin>>n; if(n == 1){puts("1");continue;} double ans = log10(sqrt(2.*Pi*n)); ans += n * log10(n/e); cout<<fixed<<setprecision(0)<<ceil(ans)<<endl; } return 0; }
时间: 2024-10-10 02:08:14