結果

問題 No.500 階乗電卓
ユーザー ぴろずぴろず
提出日時 2017-04-07 22:42:11
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 529 bytes
コンパイル時間 2,254 ms
コンパイル使用メモリ 72,992 KB
実行使用メモリ 56,024 KB
最終ジャッジ日時 2023-09-23 02:13:56
合計ジャッジ時間 6,546 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
55,724 KB
testcase_01 AC 128 ms
55,608 KB
testcase_02 AC 129 ms
55,684 KB
testcase_03 AC 129 ms
55,692 KB
testcase_04 AC 125 ms
55,928 KB
testcase_05 AC 129 ms
55,704 KB
testcase_06 AC 128 ms
55,704 KB
testcase_07 AC 126 ms
55,660 KB
testcase_08 AC 126 ms
55,908 KB
testcase_09 AC 127 ms
55,696 KB
testcase_10 WA -
testcase_11 AC 128 ms
55,656 KB
testcase_12 AC 129 ms
55,808 KB
testcase_13 AC 129 ms
55,800 KB
testcase_14 AC 129 ms
56,008 KB
testcase_15 AC 130 ms
55,472 KB
testcase_16 AC 129 ms
55,808 KB
testcase_17 AC 129 ms
55,704 KB
testcase_18 AC 128 ms
56,024 KB
testcase_19 AC 127 ms
55,656 KB
testcase_20 AC 128 ms
55,924 KB
testcase_21 AC 129 ms
55,520 KB
testcase_22 AC 136 ms
55,640 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, 1000);
		long fact = 1;
		boolean of = false;
		long fact2 = 1;
		for(int i=1;i<=n;i++) {
			fact = fact * i % MOD;
			fact2 = fact * i;
			if (fact2 >= MOD) {
				of = true;
			}
		}
		if (of) {
			System.out.println(String.format("%012d", fact));
		}else{
			System.out.println(fact);
		}
		
	}
}
0