HDU - 1042 - N! - JAVA

http://acm.hdu.edu.cn/showproblem.php?pid=1042
大数嘛,直接用JAVA。

为什么要开64路?好像我觉得会快一点……其实并没有快……

import java.io.*;
import java.util.*;
import java.math.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        while (sc.hasNext()) {
            int n = sc.nextInt();

            int anscnt = 64;
            BigInteger ans[] = new BigInteger[anscnt];

            for (int i = 0; i < anscnt; i++) {
                ans[i] = BigInteger.ONE;
            }

            for (int i = 1; i <= n; i++) {
                ans[i % anscnt] = ans[i % anscnt].multiply(BigInteger.valueOf(i));
            }

            BigInteger ANS = BigInteger.ONE;
            for (int i = 0; i < anscnt; i++) {
                ANS = ANS.multiply(ans[i]);
            }

            System.out.println(ANS);
        }

        sc.close();
    }
}

原文地址:https://www.cnblogs.com/Yinku/p/10743578.html

时间: 2024-10-27 11:54:41

HDU - 1042 - N! - JAVA的相关文章

hdu 1042 N! java大数及判断文件末尾

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

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 大数阶乘

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

HDU 1042 N! 参考代码

请问DIY题目做不来的队员:听进去了吗?去消化吸收了吗?能百度一下吗? 请问集训队员:有兴趣吗?有团队合作精神吗?有责任感吗?能坚持吗?能自主学习吗?能承受挫败吗? HDU 1042 N! 题意:Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N! (题目链接) #include <iostream> using namespace std; //每个数组元素存放5位数 const int MAX=1000000; //

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 1042 N!

题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=1042Problem 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 Input123 Sample

hdu 2023 简单java 水过~~~

Problem Description 假设一个班有n(n<=50)个学生,每人考m(m<=5)门课,求每个学生的平均成绩和每门课的平均成绩,并输出各科成绩均大于等于平均成绩的学生数量. Input 输入数据有多个测试实例,每个测试实例的第一行包括两个整数n和m,分别表示学生数和课程数.然后是n行数据,每行包括m个整数(即:考试分数). Output 对于每个测试实例,输出3行数据,第一行包含n个数据,表示n个学生的平均成绩,结果保留两位小数:第二行包含m个数据,表示m门课的平均成绩,结果保留

HDU Exponentiation 1063 Java大数题解

Exponentiation Time Limit: 1000/500 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6973    Accepted Submission(s): 1975 Problem Description Problems involving the computation of exact values of very large magnitude

hdu 4762 公式 java

n/(n)^(m-1) 1 import java.io.*; 2 import java.math.*; 3 import java.util.*; 4 5 public class Main { 6 static BigInteger gcd(BigInteger a,BigInteger b) 7 { 8 if(b.equals(BigInteger.ZERO))return a; 9 else return gcd(b,a.mod(b)); 10 } 11 public static v