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();
	}
}
posted @ 2019-04-21 00:50  韵意  阅读(180)  评论(0编辑  收藏  举报