51nod1130 N的阶乘的长度 V2(斯特林近似)

xiaoxiao2021-02-28  78

#include <cstdio> #include <cmath> #include <iostream> using namespace std; typedef long long LL; /* 斯特林公式 求n!十进制表示是多少位数 n!~sqrt(2*PI*n)*((n/e)^n) */ const double PI=acos(-1.0); int n; int main() { int t; scanf("%d",&t); while(t--) { scanf("%d",&n); LL ans = log10(2*PI*n)/2 + n*(log10(n/exp(1.0))); printf("%I64d\n",ans+1); } return 0; }
转载请注明原文地址: https://www.6miu.com/read-63932.html

最新回复(0)