結果

問題 No.2211 Frequency Table of GCD
ユーザー tentententen
提出日時 2024-04-02 18:54:29
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,175 ms / 2,000 ms
コード長 2,214 bytes
コンパイル時間 3,906 ms
コンパイル使用メモリ 89,952 KB
実行使用メモリ 72,564 KB
最終ジャッジ日時 2024-04-02 18:54:53
合計ジャッジ時間 21,464 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
54,792 KB
testcase_01 AC 69 ms
54,884 KB
testcase_02 AC 67 ms
54,884 KB
testcase_03 AC 264 ms
68,500 KB
testcase_04 AC 544 ms
68,788 KB
testcase_05 AC 710 ms
67,600 KB
testcase_06 AC 587 ms
71,344 KB
testcase_07 AC 713 ms
72,256 KB
testcase_08 AC 233 ms
60,460 KB
testcase_09 AC 184 ms
58,112 KB
testcase_10 AC 253 ms
61,356 KB
testcase_11 AC 233 ms
60,576 KB
testcase_12 AC 268 ms
59,076 KB
testcase_13 AC 504 ms
68,096 KB
testcase_14 AC 499 ms
71,280 KB
testcase_15 AC 485 ms
71,652 KB
testcase_16 AC 517 ms
71,400 KB
testcase_17 AC 651 ms
68,388 KB
testcase_18 AC 915 ms
71,728 KB
testcase_19 AC 946 ms
71,336 KB
testcase_20 AC 924 ms
72,532 KB
testcase_21 AC 924 ms
72,564 KB
testcase_22 AC 923 ms
72,120 KB
testcase_23 AC 234 ms
67,936 KB
testcase_24 AC 1,175 ms
71,616 KB
testcase_25 AC 233 ms
60,624 KB
testcase_26 AC 67 ms
54,876 KB
testcase_27 AC 959 ms
71,224 KB
testcase_28 AC 1,160 ms
72,140 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.function.*;
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 m = sc.nextInt();
        int[] counts = new int[m];
        while (n-- > 0) {
            int x = sc.nextInt();
            for (int i = 1; i <= Math.sqrt(x); i++) {
                if (x % i == 0) {
                    counts[i - 1]++;
                    if (i * i < x) {
                        counts[x / i - 1]++;
                    }
                } 
            }
        }
        long[] ans = new long[m];
        for (int i = m; i >= 1; i--) {
            long current = (pow(2, counts[i - 1]) - 1 + MOD) % MOD;
            for (int j = 2; j * i <= m; j++) {
                current += MOD - ans[j * i - 1];
                current %= MOD;
            }
            ans[i - 1] = current;
        }
        System.out.println(Arrays.stream(ans).mapToObj(String::valueOf).collect(Collectors.joining("\n")));
    }
    
    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 Scanner {
    BufferedReader br;
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
        } catch (Exception e) {
            
        }
    }
    
    public int nextInt() {
        return Integer.parseInt(next());
    }
    
    public long nextLong() {
        return Long.parseLong(next());
    }
    
    public double nextDouble() {
        return Double.parseDouble(next());
    }
    
    public String next() {
        try {
            while (!st.hasMoreTokens()) {
                st = new StringTokenizer(br.readLine());
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            return st.nextToken();
        }
    }
    
}
0