HDU - 1042 - N! - JAVA

Posted 韵意

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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();
    }
}

以上是关于HDU - 1042 - N! - JAVA的主要内容,如果未能解决你的问题,请参考以下文章

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

HDU 1042 N!

N! hdu 1042

HDU 1042 N!大数

HDU1042 N!(大数问题,万进制)

hdu1042 N!(大数求阶乘)