首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 其他相关 >

HDU 1042 N

2013-11-02 
HDU 1042 N!N!Problem DescriptionGiven an integer N(0 ≤ N ≤ 10000), your task is to calculate N! Inp

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();    }}







热点排行