HDU 1042 N!
N!
Problem DescriptionGiven an integer N(0 ≤ N ≤ 10000), your task is to calculate N!
InputOne N in one line, process to the end of file.
OutputFor each N, output N! in one line.
Sample Input123
Sample Output126
AuthorJGShining(极光炫影)
解题思路:这题用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(); }}