posts - 64, comments - 4, trackbacks - 0, articles - 0

hdu 1042 (N!)Java高精度

Posted on 2010-08-22 21:21 acronix 阅读(435) 评论(0)  编辑 收藏 引用 所属分类: zhaoboqiang解题报告
 

N!

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

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


Java解高精度的题目还是很爽的,注意类名要写成Main,Compilation Error了n次。
import java.math.*;
import java.util.
*;

public class Main {
    
public static BigInteger num;

    
public static void main(String args[]) {
        Scanner cin 
= new Scanner(System.in);
        
        
while (cin.hasNext()) {
            num 
= BigInteger.ONE;
            
int n = cin.nextInt();
            num 
= BigInteger.ONE;
            
for (int i = 1; i <= n; i++{
                num
= num.multiply(BigInteger.valueOf(i));
            }

            System.
out.println(num);
        }

    }

}

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理