读书人

HDU 1042 N

发布时间: 2013-11-02 19:41:10 作者: rapoo

HDU 1042 N!

N!
Problem DescriptionGiven an integer N(0 ≤ N ≤ 10000), your task is to calculate N!

InputOne N in one line, process to the end of file.

OutputFor each N, output N! in one line.

Sample Input
123

Sample Output
126

AuthorJGShining(极光炫影)

解题思路:这题用Java大数,而且不能预处理,预处理会超内存


import java.util.*;import java.math.*;public class Main {    public static void main(String[] args) {        Scanner scan=new Scanner(System.in);        while(scan.hasNextInt()){            int n=scan.nextInt();            BigInteger ans=new BigInteger("1");            for(int i=2;i<=n;i++){                BigInteger tmp=new BigInteger(i+"");                ans=ans.multiply(tmp);            }            System.out.println(ans);        }        scan.close();    }}







读书人网 >其他相关

热点推荐