大数的阶乘
来源:互联网 发布:css 开发工具 知乎 编辑:程序博客网 时间:2024/05/17 04:48
高精度的运算在Java中是很容易实现的,就像 a + b Problem 一样,因为Java提供了相应的类库和API;但是在 C/C++ 当中就没有那么现成的类和API来让你调用了。本着“自己动手,丰衣足食”的Coder精神,还是自己上吧。让我们一起看看如何使用 C/C++ 来进行大数的阶乘吧。
/* *From:《算法竞赛入门经典》――刘汝佳 *Author:YQ_beyond *Date:2015.03.29*//* C++当中高精度运算*/#include<iostream>#include<cstring>#include<cstdio>using namespace std;const int maxn = 3000;int res[maxn];int main(){ int i, j, n; while(1) { scanf("%d",&n); memset(res,0,sizeof(res)); res[0] = 1; int cut = 1; for(i = 1 ; i <= n ; i++) { int cnt = 0; for(j = 0;j < cut; j++) { int s = res[j] * i + cnt; res[j] = s % 10; cnt = s / 10; } for(; cnt != 0; j++) { int s = res[j] * i + cnt; res[j] = s % 10; cnt = s / 10; cut ++; } } //for(j = maxn - 1; j >= 0; j--) if(res[j]) break; for(i = cut - 1; i >= 0; i--) printf("%d",res[i]); printf("\n"); } return 0;}
0 0
- 大数阶乘-N的阶乘
- 大数的阶乘
- 模块化的大数阶乘
- mr 的大数阶乘
- 大数阶乘的算法
- 大数的阶乘
- 大数的阶乘算法
- 大数的阶乘
- 大数阶乘的求法
- 大数的阶乘
- 大数阶乘的代码
- 大数n的阶乘
- 大数的阶乘算法
- 大数的阶乘
- 大数的阶乘
- 大数n的阶乘
- 大数阶乘的实现
- 大数阶乘的实现
- Guava学习笔记目录
- Guice教程
- nagios插件之监控if8接口日志
- eXtremeDB快速入门:二
- unity爆炸特效
- 大数的阶乘
- 最大生成树+LCA倍增
- C#调用Access数据库 Like通配符的使用
- iOS开发中的UIPickerView
- C++中强制数据类型转换的原理
- Java学习(四):JRE和JDK,以及环境变量的配置
- 老板开理发店24年只收5元 顾客心疼求涨价
- Android—2015年代做安卓毕业设计 Android毕业设计毕业设计AndroidAPP
- OpenGL学习笔记-2015.3.24——transform feedback缓存&粒子系统示例分析