結果

問題 No.500 階乗電卓
ユーザー ぴろずぴろず
提出日時 2017-04-07 22:47:19
言語 Java19
(openjdk 21)
結果
AC  
実行時間 114 ms / 2,000 ms
コード長 529 bytes
コンパイル時間 3,057 ms
コンパイル使用メモリ 71,284 KB
実行使用メモリ 56,292 KB
最終ジャッジ日時 2023-09-07 08:31:37
合計ジャッジ時間 6,607 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
55,816 KB
testcase_01 AC 110 ms
55,948 KB
testcase_02 AC 110 ms
55,664 KB
testcase_03 AC 112 ms
55,316 KB
testcase_04 AC 112 ms
55,564 KB
testcase_05 AC 109 ms
55,948 KB
testcase_06 AC 111 ms
55,624 KB
testcase_07 AC 110 ms
53,488 KB
testcase_08 AC 113 ms
55,900 KB
testcase_09 AC 108 ms
55,532 KB
testcase_10 AC 106 ms
55,696 KB
testcase_11 AC 109 ms
55,792 KB
testcase_12 AC 110 ms
55,776 KB
testcase_13 AC 111 ms
55,796 KB
testcase_14 AC 108 ms
55,500 KB
testcase_15 AC 109 ms
56,292 KB
testcase_16 AC 112 ms
56,000 KB
testcase_17 AC 109 ms
55,832 KB
testcase_18 AC 113 ms
55,756 KB
testcase_19 AC 109 ms
55,992 KB
testcase_20 AC 114 ms
55,524 KB
testcase_21 AC 114 ms
55,556 KB
testcase_22 AC 113 ms
56,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package no500;

import java.util.Scanner;

public class Main {
	public static long MOD = 1000000000000L;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		n = Math.min(n, 100);
		long fact = 1;
		boolean of = false;
		long fact2 = 1;
		for(int i=1;i<=n;i++) {
			fact = fact * i % MOD;
			fact2 = fact2 * i;
			if (fact2 >= MOD) {
				of = true;
			}
		}
		if (of) {
			System.out.println(String.format("%012d", fact));
		}else{
			System.out.println(fact);
		}
		
	}
}
0