点击打开题目
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 74697 Accepted Submission(s): 21717
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
3Sample Output
1
2
6Author
JGShining(极光炫影)
用java算大数真的很方便啊!
代码如下:
import java.math.BigDecimal;
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
while (sc.hasNext())
{
int n = sc.nextInt();
BigDecimal ans=new BigDecimal(1);
for (int i = 2 ; i <= n ; i++)
{
BigDecimal t = new BigDecimal(i);
ans = ans.multiply(t);
}
System.out.println(ans);
}
}
}