N!

来源:互联网 发布:农网改造包工怎么算法 编辑:程序博客网 时间:2024/04/28 14:31
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
123
 

Sample Output
126


此题主要是解决在a.multiply(i)再mulitply()中不能够用整形,必须是大整形所以可以改为multiply(new BigInteger(""+i)  );


import java.util.*;import java.io.*;import java.math.*;public class Main{  static BigInteger[] ans;//注意定义大数的数组的放法再BigInteger后边加上数组的符号[].public static void main(String[] args){Scanner cin=new Scanner(System.in);//BigInteger i;int i,n;ans=new BigInteger[10010];ans[0]=BigInteger.valueOf(1);ans[1]=BigInteger.valueOf(1);ans[2]=BigInteger.valueOf(2);for(i=3;i<=10001;i++){ans[i]=ans[i-1].multiply(new BigInteger(""+i)   );}while(cin.hasNext()){n=cin.nextInt();System.out.println(ans[n]);}}}


0 0
原创粉丝点击