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
1
2
3
Sample Output
1
2
6
先打表(打表的含義是先將範圍內的所有結果求出,然後根據輸出輸出具體結果)。
import java.math.BigInteger;
import java.util.Scanner;
public class P1042 {
BigInteger[] bigArray = new BigInteger[10001];
public static void main(String[] args) {
new P1042().run();
}
public void run(){
Scanner scanner = new Scanner(System.in);
initial();
int n;
while (scanner.hasNext()) {
n = scanner.nextInt();
System.out.println(bigArray[n]);
}
scanner.close();
}
public void initial(){
bigArray[0] = BigInteger.ONE;
bigArray[1] = BigInteger.ONE;
for (int i = 2; i < 10001; i++) {
bigArray[i] = bigArray[i - 1].multiply(BigInteger.valueOf(i));
}
}
}