結果

問題 No.1396 Giri
ユーザー tentententen
提出日時 2021-11-08 14:11:21
言語 Java21
(openjdk 21)
結果
AC  
実行時間 116 ms / 2,000 ms
コード長 1,907 bytes
コンパイル時間 2,709 ms
コンパイル使用メモリ 77,428 KB
実行使用メモリ 56,036 KB
最終ジャッジ日時 2024-04-27 21:12:53
合計ジャッジ時間 5,749 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
50,248 KB
testcase_01 AC 55 ms
50,048 KB
testcase_02 AC 112 ms
55,904 KB
testcase_03 AC 55 ms
50,496 KB
testcase_04 AC 53 ms
50,472 KB
testcase_05 AC 114 ms
56,036 KB
testcase_06 AC 53 ms
50,372 KB
testcase_07 AC 54 ms
50,156 KB
testcase_08 AC 55 ms
50,372 KB
testcase_09 AC 53 ms
50,200 KB
testcase_10 AC 54 ms
50,236 KB
testcase_11 AC 52 ms
50,388 KB
testcase_12 AC 54 ms
50,432 KB
testcase_13 AC 53 ms
50,408 KB
testcase_14 AC 53 ms
50,096 KB
testcase_15 AC 53 ms
50,244 KB
testcase_16 AC 55 ms
50,284 KB
testcase_17 AC 56 ms
50,284 KB
testcase_18 AC 82 ms
50,996 KB
testcase_19 AC 100 ms
53,396 KB
testcase_20 AC 107 ms
53,856 KB
testcase_21 AC 112 ms
53,988 KB
testcase_22 AC 114 ms
55,936 KB
testcase_23 AC 116 ms
55,860 KB
testcase_24 AC 113 ms
55,984 KB
testcase_25 AC 113 ms
55,992 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static final int MOD = 998244353;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        boolean[] isNotPrime = new boolean[n + 1];
        int[] number = new int[n + 1];
        for (int i = 2; i <= n; i++) {
            number[i] = i;
            if (!isNotPrime[i]) {
                for (int j = 2; j * i <= n; j++) {
                    isNotPrime[j * i] = true;
                }
            }
        }
        int max = 0;
        for (int i = n; i >= 2; i--) {
            if (!isNotPrime[i]) {
                max = i;
                break;
            }
        }
        long ans = 1;
        for (int i = 2; i <= n; i++) {
            if (i == max) {
                continue;
            }
            if (number[i] <= 1) {
                continue;
            }
            ans *= number[i];
            ans %= MOD;
            for (int j = 2; j * i <= n; j++) {
                number[j * i] /= number[i];
            }
        }
        System.out.println(ans);
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    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 String nextLine() throws Exception {
        return br.readLine();
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0