結果

問題 No.1396 Giri
ユーザー tentententen
提出日時 2023-04-25 12:49:23
言語 Java21
(openjdk 21)
結果
AC  
実行時間 104 ms / 2,000 ms
コード長 2,249 bytes
コンパイル時間 2,743 ms
コンパイル使用メモリ 90,240 KB
実行使用メモリ 42,484 KB
最終ジャッジ日時 2024-04-26 18:37:08
合計ジャッジ時間 5,480 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
37,144 KB
testcase_01 AC 52 ms
37,128 KB
testcase_02 AC 104 ms
42,120 KB
testcase_03 AC 49 ms
36,964 KB
testcase_04 AC 50 ms
36,732 KB
testcase_05 AC 96 ms
42,264 KB
testcase_06 AC 49 ms
37,164 KB
testcase_07 AC 49 ms
36,940 KB
testcase_08 AC 49 ms
36,980 KB
testcase_09 AC 48 ms
37,220 KB
testcase_10 AC 51 ms
36,660 KB
testcase_11 AC 47 ms
37,120 KB
testcase_12 AC 48 ms
37,128 KB
testcase_13 AC 49 ms
36,964 KB
testcase_14 AC 48 ms
37,168 KB
testcase_15 AC 48 ms
36,864 KB
testcase_16 AC 47 ms
36,740 KB
testcase_17 AC 50 ms
36,792 KB
testcase_18 AC 60 ms
37,640 KB
testcase_19 AC 78 ms
40,300 KB
testcase_20 AC 86 ms
41,028 KB
testcase_21 AC 90 ms
41,904 KB
testcase_22 AC 93 ms
41,952 KB
testcase_23 AC 96 ms
42,460 KB
testcase_24 AC 96 ms
42,484 KB
testcase_25 AC 94 ms
42,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    static final int MOD = 998244353;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int[] values = new int[n + 1];
        Arrays.fill(values, 1);
        int max = 0;
        long ans = 1;
        for (int i = 2; i <= n; i++) {
            values[i] = i / values[i];
            ans *= values[i];
            ans %= MOD;
            if (values[i] > 1) {
                max = Math.max(max, values[i]);
                for (int j = 2; j * i <= n; j++) {
                    values[j * i] *= values[i];
                }
            }
        }
        System.out.println(ans * pow(max, MOD - 2) % MOD);
    }
    
    static long pow(long x, int p) {
        if (p == 0) {
            return 1;
        } else if (p % 2 == 0) {
            return pow(x * x % MOD, p / 2);
        } else {
            return pow(x, p - 1) * x % MOD;
        }
    }
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0