結果

問題 No.2211 Frequency Table of GCD
ユーザー LyricalMaestro
提出日時 2024-10-30 01:05:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,432 ms / 2,000 ms
コード長 999 bytes
コンパイル時間 320 ms
コンパイル使用メモリ 82,460 KB
実行使用メモリ 122,124 KB
最終ジャッジ日時 2024-10-30 01:05:34
合計ジャッジ時間 13,748 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

## https://yukicoder.me/problems/no/2211

MOD = 998244353

import math

def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))

    a_map = {}
    for a in A:
        if a not in a_map:
            a_map[a] = 0
        a_map[a] += 1

    gcd_array = [0] * (M + 1)
    for a, num in a_map.items():

        sqrt_a = int(math.sqrt(a))
        for p in range(1, sqrt_a + 1):
            if a % p == 0:
                q = a // p
                gcd_array[p] += num
                if q != p:
                    gcd_array[q] += num
    
    # 答えを出す
    answer = [0] * (M + 1)
    for m in reversed(range(1, M + 1)):
        if gcd_array[m] == 0:
            continue

        ans = (pow(2, gcd_array[m], MOD) - 1) % MOD
        x = 2 * m
        while x <= M:
            ans -= answer[x]
            ans %= MOD
            x += m
        answer[m] = ans
    
    for i in range(1, M + 1):
        print(answer[i])






if __name__ == "__main__":
    main()
0