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.
分析:题意很简单,求n的阶乘,重点在于N极大,已经超过了long long
C++应该用模拟数组,但是Java中提供了大数类,更加简便
import java.math.BigInteger;
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
int i;
while(input.hasNext())
{
int n=input.nextInt();
BigInteger ans=BigInteger.ONE;
for(i=1;i<=n;i++)
{
ans=ans.multiply(BigInteger.valueOf(i));
}
System.out.println(ans);
}
}
}