HDU 1042 N! -- 求阶乘 java大法好

来源:互联网 发布:gta5捏脸数据女日本 编辑:程序博客网 时间:2024/06/11 01:56

N!

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 72968    Accepted Submission(s): 21130


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
 

import java.math.BigInteger;import java.util.Scanner;public class Main {    public static void main(String[] args) {        Scanner cin = new Scanner(System.in);        BigInteger [] a = new BigInteger[10005];        a[0] = BigInteger.ONE;        for(int i=1;i<=10000;i++){            a[i] = BigInteger.valueOf(i).multiply(a[i-1]);        }        while(cin.hasNext()){            int n = cin.nextInt();            System.out.println(a[n]);        }    }}

0 0
原创粉丝点击