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

时间: 2024-12-29 10:54:56

HDU 1042-N!(大数类)的相关文章

多校第六场 HDU 4927 JAVA大数类

题目大意:给定一个长度为n的序列a,每次生成一个新的序列,长度为n-1,新序列b中bi=ai+1?ai,直到序列长度为1.输出最后的数. 思路:这题实在是太晕了,比赛的时候搞了四个小时,从T到WA,唉--对算组合还是不太了解啊,现在对组合算比较什么了-- import java.io.*; import java.math.*; import java.util.*; public class Main { public static void main(String[] args) { Sca

hdu 1042 N!(大数阶乘,转化为100000这样的比较大的进制)

N! Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 54172    Accepted Submission(s): 15365 Problem Description Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N! Input One N in one

HDU 1042 N! (大数阶乘,还是Java大法好,C也不能错过!!!)

N! Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 73270    Accepted Submission(s): 21210 Problem Description Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N! Input One N in o

HDU 5050 Java 大数类+读入二进制

http://acm.hdu.edu.cn/showproblem.php?pid=5050 才知道 原来JAVA这么好用,连二进制都封装好了 in.nextBigInteger(2)  就是按二进制读入 当然a.gcd(b).toString(2)  是按二进制输出一个二进制String,  a,b是大数 另外,JAVA交代码原来是class Main import java.math.BigInteger; import java.util.Scanner; public class Mai

HDU 1042 N!(大数阶乘)

N! 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 代码: 1 #include<cstdio> 2 usi

HDU高精度总结(java大数类)

  HDU1002   A + B Problem II [题意]大数相加 [链接]http://acm.hdu.edu.cn/showproblem.php?pid=1002 Sample Input 2 1 2 112233445566778899 998877665544332211 Sample Output Case 1: 1 + 2 = 3 Case 2: 112233445566778899 + 998877665544332211 = 1111111111111111110 代码

HDU 5047 Sawtooth (JAVA大数类)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5047 题面: Sawtooth Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 1636    Accepted Submission(s): 637 Problem Description Think about a plane: ● O

HDU 1042 大数阶乘

B - 2 Time Limit:5000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 1042 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. Outpu

java大数类

NYOJ 773  开方数 http://acm.nyist.net/JudgeOnline/problem.php?pid=773 1 import java.util.Scanner; 2 3 public class Main{ 4 public static void main(String[] args){ 5 int n; 6 double p; 7 Scanner cin = new Scanner(System.in); 8 while(true){ 9 n = cin.next