hdu 1042 N!
来源:互联网 发布:java能做什么游戏 编辑:程序博客网 时间:2024/06/05 17:15
N!
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 53746 Accepted Submission(s): 15203
Problem Description
Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N!
Input
One N in one line, process to the end of file.
Output
For each N, output N! in one line.
Sample Input
123
Sample Output
126
求n的阶乘。
模拟乘法运算,很精辟的算法!!
#include <iostream>#include <cstdio>#include <cstring>using namespace std;#define maxn 50000int p[maxn];int main(){ int n; while(cin >> n) { memset(p,0,sizeof(p)); p[0] = 1; for(int i=2;i<=n;i++) { int c = 0; for(int j=0;j<maxn;j++) { int x = p[j]*i + c; p[j] = x%10; c = x/10; } } int s = maxn-1; while(p[s]==0) s--; for(int i=s;i>=0;i--) { printf("%d",p[i]); } printf("\n"); } return 0;}
0 0
- N! ---HDU 1042
- HDU 1042 N!
- hdu 1042 N!
- HDU 1042 N!
- HDU 1042 N!
- hdu 1042 N!
- hdu 1042 N!
- HDU 1042 - N!
- hdu 1042 N!
- hdu 1042 N!
- HDU 1042 N!
- hdu 1042 N!
- HDU 1042 N!
- HDU 1042 N!
- Hdu 1042 - N!
- hdu 1042 N!
- hdu 1042 N!
- hdu 1042 N!
- hdu 1047 Integer Inquiry
- HDU 2604 Queuing (矩阵快速幂)
- ubuntu 配置java
- (c语法百题12)优惠购物
- scala eclipse sbt 应用程序开发
- hdu 1042 N!
- HDU 1757 A Simple Math Problem (矩阵快速幂)
- HDU4908 - BestCoder Sequence(BestCoder Round #3 计数)
- 思科网络技术学院教程——实验——在Packet Tracer中使用TCP/IP协议和OSI模型
- 【eclipse插件开发实战】Eclipse插件开发7——插件发布jar包
- 第二十三周工作总结
- javascript-1
- 广播和泛洪的区别
- jqGrid中的编辑