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

猜你喜欢

转载自www.cnblogs.com/Yinku/p/10743578.html