結果

問題 No.502 階乗を計算するだけ
ユーザー 37zigen37zigen
提出日時 2017-04-07 23:22:04
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 1,975 bytes
コンパイル時間 2,281 ms
コンパイル使用メモリ 74,672 KB
実行使用メモリ 57,852 KB
最終ジャッジ日時 2023-09-23 02:43:06
合計ジャッジ時間 11,535 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
55,536 KB
testcase_01 AC 126 ms
55,988 KB
testcase_02 AC 127 ms
55,752 KB
testcase_03 AC 125 ms
55,796 KB
testcase_04 AC 125 ms
55,932 KB
testcase_05 AC 124 ms
55,692 KB
testcase_06 AC 126 ms
55,772 KB
testcase_07 AC 125 ms
55,768 KB
testcase_08 AC 126 ms
55,984 KB
testcase_09 AC 129 ms
56,060 KB
testcase_10 AC 127 ms
55,788 KB
testcase_11 AC 127 ms
55,772 KB
testcase_12 AC 127 ms
55,724 KB
testcase_13 AC 126 ms
55,776 KB
testcase_14 AC 127 ms
55,888 KB
testcase_15 AC 130 ms
55,716 KB
testcase_16 AC 129 ms
55,780 KB
testcase_17 AC 128 ms
55,508 KB
testcase_18 AC 125 ms
56,020 KB
testcase_19 AC 126 ms
55,980 KB
testcase_20 AC 125 ms
56,096 KB
testcase_21 AC 124 ms
56,052 KB
testcase_22 AC 147 ms
55,780 KB
testcase_23 AC 137 ms
55,504 KB
testcase_24 AC 145 ms
56,068 KB
testcase_25 AC 128 ms
55,972 KB
testcase_26 AC 137 ms
55,944 KB
testcase_27 AC 133 ms
57,584 KB
testcase_28 AC 135 ms
56,024 KB
testcase_29 AC 132 ms
55,920 KB
testcase_30 AC 146 ms
55,748 KB
testcase_31 AC 137 ms
55,796 KB
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 AC 140 ms
55,580 KB
testcase_41 RE -
testcase_42 AC 123 ms
55,816 KB
testcase_43 AC 126 ms
55,496 KB
testcase_44 AC 126 ms
56,324 KB
testcase_45 AC 124 ms
56,204 KB
testcase_46 AC 124 ms
55,876 KB
testcase_47 AC 125 ms
55,704 KB
testcase_48 AC 124 ms
55,684 KB
testcase_49 AC 124 ms
55,748 KB
testcase_50 AC 125 ms
55,920 KB
testcase_51 AC 123 ms
56,120 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long mod = (long) (1e9 + 7);
		if (n >= mod) {
			System.out.println(0);
			return;
		}
		long[] pre = new long[] { 1, 641102369, 578095319, 5832229, 259081142, 974067448, 316220877, 690120224,
				251368199, 980250487, 682498929, 134623568, 95936601, 933097914, 167332441, 598816162, 336060741,
				248744620, 626497524, 288843364, 491101308, 245341950, 565768255, 246899319, 968999, 586350670,
				638587686, 881746146, 19426633, 850500036, 76479948, 268124147, 842267748, 886294336, 485348706,
				463847391, 544075857, 898187927, 798967520, 82926604, 723816384, 156530778, 721996174, 299085602,
				323604647, 172827403, 398699886, 530389102, 294587621, 813805606, 67347853, 497478507, 196447201,
				722054885, 228338256, 407719831, 762479457, 746536789, 811667359, 778773518, 27368307, 438371670,
				59469516, 5974669, 766196482, 606322308, 86609485, 889750731, 340941507, 371263376, 625544428,
				788878910, 808412394, 996952918, 585237443, 1669644, 361786913, 480748381, 595143852, 837229828,
				199888908, 526807168, 579691190, 145404005, 459188207, 534491822, 439729802, 840398449, 899297830,
				235861787, 888050723, 656116726, 736550105, 440902696, 85990869, 884343068, 56305184, 973478770,
				168891766, 804805577, 927880474, 876297919, 934814019, 676405347, 567277637, 112249297, 44930135,
				39417871, 47401357, 108819476, 281863274, 60168088, 692636218, 432775082, 14235602, 770511792,
				400295761, 697066277, 421835306, 220108638 };
		int q = (int) (n / (1e6));
		long cur = pre[q];
		n %= (1e6);
		for (long i = (long) ((1e6) * q + 1); i <= 1e6 * q + n; ++i) {
			cur = (cur * i) % mod;
		}
		System.out.println(cur);
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}
0