結果

問題 No.2075 GCD Subsequence
ユーザー lam6er
提出日時 2025-03-31 17:25:08
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 976 bytes
コンパイル時間 204 ms
コンパイル使用メモリ 82,588 KB
実行使用メモリ 125,196 KB
最終ジャッジ日時 2025-03-31 17:25:47
合計ジャッジ時間 8,013 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 2 WA * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

MOD = 998244353

def main():
    max_a = 10**6
    spf = list(range(max_a + 1))
    for i in range(2, int(max_a**0.5) + 1):
        if spf[i] == i:
            for j in range(i*i, max_a + 1, i):
                if spf[j] == j:
                    spf[j] = i

    def get_factors(x):
        if x == 1:
            return set()
        factors = set()
        while x != 1:
            p = spf[x]
            factors.add(p)
            while x % p == 0:
                x //= p
        return factors

    input = sys.stdin.read().split()
    n = int(input[0])
    a = list(map(int, input[1:n+1]))

    cnt = dict()
    ans = 0

    for num in a:
        factors = get_factors(num)
        s = 0
        for p in factors:
            s = (s + cnt.get(p, 0)) % MOD
        delta = (s + 1) % MOD
        ans = (ans + delta) % MOD
        for p in factors:
            cnt[p] = (cnt.get(p, 0) + delta) % MOD

    print(ans % MOD)

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