HDU 1042 (大数)
来源:互联网 发布:app制作编程 编辑:程序博客网 时间:2024/05/18 02:14
N!
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 56027 Accepted Submission(s): 15904
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
126C++版:#include "stdio.h"#include "string.h"#define N 100000int f[N];int main(){int i,j,n,c;int k=1;while(scanf("%d",&n)!=EOF) {memset(f,0,sizeof(f)); f[0]=1; for(i=2;i<=n;i++) { c=0; for(j=0;j<=k;j++) {int s=f[j]*i+c; f[j]=s%10; c=s/10; if(k==j && c!=0) k++; } } for(j=k;j>=0;j--) if(f[j]) break; for(i=j;i>=0;i--) printf("%d",f[i]); printf("\n"); } return 0; }Java版import java.io.BufferedInputStream;import java.math.BigInteger;import java.util.Scanner;public class Main { public static void main(String[] args) { Scanner cin=new Scanner (new BufferedInputStream(System.in));int n;BigInteger a,b;while(cin.hasNext()){n=cin.nextInt();b=BigInteger.ONE;a=BigInteger.ONE;for(int i=2;i<=n;i++){a=a.multiply(BigInteger.valueOf(i));}System.out.println(a);}}}
0 0
- HDU-1042(大数阶乘)
- hdu 1042 大数阶乘
- hdu 1042 大数 N!
- hdu 1042 N!(大数)
- HDU 1042 大数阶乘...
- HDU 1042(大数)
- hdu-1042-N!(大数)
- HDU 1042 (大数)
- HDU 1042(大数)
- HDU 1042--N! 【大数】
- HDU 1042 N!【大数】
- HDU 1042 大数阶乘
- HDU 1042 N!(大数)
- hdu 1042 大数阶乘 ,
- HDU 1042 大数
- HDU N! 1042 大数
- HDU-1042(java 大数)
- hdu 1042 N! 大数相乘。
- baidu自动根据ip定位当前省市
- linux系统结构
- poj 2386 Lake Counting
- LeetCode: Combination Sum II
- 机器学习——2. 从最大似然再看线性回归
- HDU 1042 (大数)
- ECMAScript5中getter和setter的使用
- Vi删除操作大全
- LeetCode 题解(59): Reverse Linked List II
- pcm写入wav文件
- 第九周项目五 程序填充题 (2)
- MVC前端与后端校验
- 在MyEclipse创建Filter
- 《JAVA与模式》之调停者模式