N!
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 73973 Accepted Submission(s): 21474
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
题意:
求n 的阶乘。
思路:
在熟悉下JAVA大数。
直接每一次输入n,循环n次就过了,只不过不能提前打表,跑不出来。。。
题意:
求n 的阶乘。
思路:
在熟悉下JAVA大数。
直接每一次输入n,循环n次就过了,只不过不能提前打表,跑不出来。。。
import java.util.Scanner;
import java.math.BigInteger;
public class Main {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
while(cin.hasNext()){
int n = cin.nextInt();
BigInteger a = BigInteger.valueOf(1);
for (int i = 1; i <= n; ++i){
BigInteger unit = BigInteger.valueOf(i);
a = a.multiply(unit);
}
System.out.println(a.toString());
}
}
}