N!
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 43577 Accepted Submission(s): 12239
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 6import java.math.BigInteger; import java.util.Scanner; public class dashu { public static void main(String[] args) { Scanner input = new Scanner(System.in); while(input.hasNext()){ BigInteger n = input.nextBigInteger(); BigInteger sum = BigInteger.valueOf(1); for(BigInteger i=BigInteger.valueOf(1); ; i=i.add(BigInteger.valueOf(1))){ if(i.compareTo(n)>0){ break; } sum = sum.multiply(i); } System.out.println(sum.toString()); } } }