51nod 1130 阶乘长度 [Stirling公式]
来源:互联网 发布:最高人民法院网络拍卖 编辑:程序博客网 时间:2024/04/30 11:26
输出n!的位数
n! 约等于 根号下(2πn) * (n/e )^n
那么 res = 1/2*lg(2πn) + nlg(n/e) + 1
实测n很小也是正确的答案
#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<cmath>#include<vector>#include<queue>#include<stack>#include<map>#include<set>#include<string>#include<iomanip>#include<ctime>#include<climits>#include<cctype>#include<algorithm>#ifdef WIN32#define AUTO "%I64d"#else#define AUTO "%lld"#endifusing namespace std;#define smax(x,tmp) x=max((x),(tmp))#define smin(x,tmp) x=min((x),(tmp))#define maxx(x1,x2,x3) max(max(x1,x2),x3)#define minn(x1,x2,x3) min(min(x1,x2),x3)const int INF=0x3f3f3f3f;const double pi = M_PI;const double e = M_E;const double eps = 1e-7;typedef long long LL;inline LL get_res(int n){ if(n<=10) { int tot = 1; for(int i=1;i<=n;i++) tot *= i; return floor(log10(tot) + eps) + 1; } return floor(0.5*log10(2*pi*(double)n) + (double)n*log10((double)n/e) + eps) + 1;}int main(){ freopen("stirling.in","r",stdin); freopen("stirling.out","w",stdout); int cas; scanf("%d",&cas); while(cas--) { int n; scanf("%d",&n); LL ans = get_res(n); printf(AUTO"\n",ans); } return 0;}
公式链接:
http://m.blog.csdn.net/article/details?id=51145807
Summary:
cmath里面有π和e的精确值!!!!!!
0 0
- 51nod 1130 阶乘长度 [Stirling公式]
- 51nod 1058 N的阶乘的长度 (Stirling公式)
- 51nod 1130 N的阶乘的长度(阶乘近似公式--斯特林公式)
- 51NOD 求n的阶乘的长度(斯特林公式)
- 51nod 1130 1157 求阶乘结果长度(斯特林公式)
- 【51nod】1130 N的阶乘的长度 V2 斯特灵公式
- 51nod 1130 N的阶乘的长度 V2(斯特林近似) 【数学】【斯特林公式】
- 51Nod关于n的阶乘的长度(斯特林公式近似计算阶乘)
- 51nod 1058 N的阶乘的长度(斯特林公式)
- HDU 1018 阶乘的位数 stirling公式
- poj 1423 stirling公式(阶乘的位数)
- 51 nod 1130 N的阶乘的长度 V2(斯特林近似)
- 51nod 1130 N的阶乘的长度V2(斯特林近似)
- 51nod-1130 N的阶乘的长度 V2(斯特林近似)
- 51nod 1130 N的阶乘的长度 V2(斯特林近似)
- 51nod 1130 N的阶乘的长度 V2(斯特林近似)
- 51nod 1130 N的阶乘的长度 V2(斯特林近似)
- 51nod 1130 N的阶乘的长度 V2(斯特林近似)
- TCP连接的三次握手
- CODEVS 1073 家族 并查集模板
- Jdbc查询数据库处理结果集优化查询代码
- **JQUERY** jQuery遍历
- 创建线程的两种方式
- 51nod 1130 阶乘长度 [Stirling公式]
- 置换 置换群 应用
- Java反射(二):反射的使用
- mysql主从复制
- hibernate debug学习总结
- 5.机器学习实战之Logistic回归
- C++中substr函数的用法
- BZOJ 1642: [Usaco2007 Nov]Milking Time 挤奶时间
- 杂花生树(四)