HDU 1042 N!(大数阶乘)
2015-07-24 18:10
281 查看
N!
[align=left]Problem Description[/align]Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N!
[align=left]Input[/align]
One N in one line, process to the end of file.
[align=left]Output[/align]
For each N, output N! in one line.
[align=left]Sample Input[/align]
1
2
3
[align=left]Sample Output[/align]
1
2
6
代码:
#include<cstdio> using namespace std; int main() { int i,n,digit,temp,carry,j; int a[40005]; while(scanf("%d",&n)!=EOF) { a[0]=1; digit=0; for(i=2;i<=n;i++) { for(carry=0,j=0;j<=digit;j++) { temp=a[j]*i+carry; a[j]=temp%10; carry=temp/10; } while(carry) { a[++digit]=carry%10; carry/=10; } } for(i=digit;i>=0;i--) printf("%d",a[i]); printf("\n"); } return 0; }
相关文章推荐
- UNIX环境编程学习——反思认识
- mongodb 嵌套查询
- Unity3D占用内存太大的解决方法
- android代码的形式让button变成圆角 透明,如图
- RobotFramework 自定义Library
- Docker ssh远程连接使用
- 页面加载之前显示正在加载
- RobotFramework 自定义Library
- 时间不同步问题导致hive 只能select* 不能select count(*)select 某个字段 ,是因
- java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
- jquery的jsonp的使用
- Java 四种引用
- 暑假集训——贪心专题——I题
- vim编辑器锁住,ctrl+S,ctrl+Q
- hive union all 数据丢失问题优化
- pipe练习(暂存)
- HDU 1002--A + B Problem II【大数】
- Android 真机测试应用
- 注册页面的验证码的实现
- HDU 2005 第几天?