码迷,mamicode.com
首页 > 编程语言 > 详细

HDU - 1042 - N! - JAVA

时间:2019-04-21 10:17:38      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:exti   rgs   print   asn   problem   value   int()   没有   show   

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

标签:exti   rgs   print   asn   problem   value   int()   没有   show   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!