设为首页 加入收藏

TOP

HDU 1042-N!(大数类)
2015-07-20 17:41:01 来源: 作者: 【 】 浏览:2
Tags:HDU 1042-N 大数

N!

Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 54761 Accepted Submission(s): 15578


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求10000以内的阶乘。java+暴力。。。
import java.io.*;
import java.util.*;
import java.math.*;
public class Main {
       public static void main(String[] args){
    	   Scanner in=new Scanner(System.in);
    	   int n,i;BigInteger ans,t;
    	   while(in.hasNext()){
    		   n=in.nextInt();
    		   ans=new BigInteger("1");
    		   for(i=1;i<=n;i++){
    			   t=new BigInteger(Integer.toString(i));
    			   ans=ans.multiply(t);
    		   }
    		   System.out.println(ans);
    	   }
       }
}
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇POJ 1127 Jack Straws (线段相交.. 下一篇Effective STL: 将vector和string..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·用 C 语言或者限制使 (2025-12-25 08:50:05)
·C++构造shared_ptr为 (2025-12-25 08:50:01)
·既然引用计数在做 GC (2025-12-25 08:49:59)
·Java 编程和 c 语言 (2025-12-25 08:19:48)
·. net内存管理宝典这 (2025-12-25 08:19:46)