N!
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
Author
JGShining(极光炫影)
解题思路:这题用Java大数,而且不能预处理,预处理会超内存
import java.util.*;
import java.math.*;
public class Main {
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
while(scan.hasNextInt()){
int n=scan.nextInt();
BigInteger ans=new BigInteger("1");
for(int i=2;i<=n;i++){
BigInteger tmp=new BigInteger(i+"");
ans=ans.multiply(tmp);
}
System.out.println(ans);
}
scan.close();
}
}