N! (n的阶乘)(大数阶乘)

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

import java.math.BigInteger;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
        Scanner in = new Scanner(System.in);
        while(in.hasNext()) //多组输入输出
        {
        	BigInteger sum = new BigInteger("1");//对sum赋初始值
        	int n = in.nextInt(); //当n超过30时,就需要用大数类
        	int i;
        	for(i = 1; i <= n; i++)
        	{
        		BigInteger num = new BigInteger(String.valueOf(i));//将i变成大数形式
        		sum = sum.multiply(num);
        	}
        	System.out.println(sum);
        }
	}

}

猜你喜欢

转载自blog.csdn.net/qq_42819248/article/details/83997593