結果

問題 No.1396 Giri
ユーザー tentententen
提出日時 2021-02-18 11:30:13
言語 Java21
(openjdk 21)
結果
AC  
実行時間 166 ms / 2,000 ms
コード長 1,007 bytes
コンパイル時間 2,002 ms
コンパイル使用メモリ 71,900 KB
実行使用メモリ 60,248 KB
最終ジャッジ日時 2023-10-12 20:08:00
合計ジャッジ時間 7,440 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
55,884 KB
testcase_01 AC 126 ms
56,056 KB
testcase_02 AC 165 ms
59,848 KB
testcase_03 AC 126 ms
55,648 KB
testcase_04 AC 130 ms
55,860 KB
testcase_05 AC 166 ms
60,052 KB
testcase_06 AC 127 ms
56,004 KB
testcase_07 AC 125 ms
55,800 KB
testcase_08 AC 126 ms
56,020 KB
testcase_09 AC 126 ms
55,704 KB
testcase_10 AC 126 ms
53,920 KB
testcase_11 AC 129 ms
56,056 KB
testcase_12 AC 127 ms
55,988 KB
testcase_13 AC 126 ms
55,840 KB
testcase_14 AC 126 ms
55,724 KB
testcase_15 AC 126 ms
55,852 KB
testcase_16 AC 127 ms
55,892 KB
testcase_17 AC 130 ms
55,868 KB
testcase_18 AC 136 ms
55,964 KB
testcase_19 AC 149 ms
57,876 KB
testcase_20 AC 156 ms
57,860 KB
testcase_21 AC 164 ms
57,952 KB
testcase_22 AC 163 ms
59,920 KB
testcase_23 AC 166 ms
59,560 KB
testcase_24 AC 163 ms
60,248 KB
testcase_25 AC 165 ms
59,972 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static final int MOD = 998244353;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] values = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            values[i] = i;
        }
        for (int i = n; i >= 1; i--) {
            if (isPrime(i)) {
                values[i] = 1;
                break;
            }
        }
        long ans = 1;
        for (int i = 2; i <= n; i++) {
            ans *= values[i];
            ans %= MOD;
            if (values[i] == 1) {
                continue;
            }
            for (int j = 2; j * i <= n; j++) {
                values[j * i] /= values[i];
            }
        }
        System.out.println(ans);
    }
    
    static boolean isPrime(int x) {
        for (int i = 2; i <= Math.sqrt(x); i++) {
            if (x % i == 0) {
                return false;
            }
        }
        return true;
    }
}
0