結果

問題 No.500 階乗電卓
ユーザー htensaihtensai
提出日時 2019-12-10 10:09:18
言語 Java21
(openjdk 21)
結果
AC  
実行時間 125 ms / 2,000 ms
コード長 732 bytes
コンパイル時間 2,691 ms
コンパイル使用メモリ 74,972 KB
実行使用メモリ 56,276 KB
最終ジャッジ日時 2023-09-06 03:38:52
合計ジャッジ時間 7,341 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
55,724 KB
testcase_01 AC 119 ms
56,016 KB
testcase_02 AC 118 ms
55,876 KB
testcase_03 AC 119 ms
55,724 KB
testcase_04 AC 118 ms
55,948 KB
testcase_05 AC 118 ms
55,804 KB
testcase_06 AC 125 ms
56,076 KB
testcase_07 AC 125 ms
55,540 KB
testcase_08 AC 120 ms
56,108 KB
testcase_09 AC 119 ms
55,892 KB
testcase_10 AC 119 ms
55,996 KB
testcase_11 AC 121 ms
55,440 KB
testcase_12 AC 120 ms
55,544 KB
testcase_13 AC 123 ms
55,904 KB
testcase_14 AC 120 ms
55,784 KB
testcase_15 AC 120 ms
55,796 KB
testcase_16 AC 121 ms
55,740 KB
testcase_17 AC 120 ms
55,772 KB
testcase_18 AC 118 ms
56,156 KB
testcase_19 AC 118 ms
56,012 KB
testcase_20 AC 121 ms
56,276 KB
testcase_21 AC 119 ms
56,236 KB
testcase_22 AC 125 ms
55,644 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

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