結果

問題 No.2075 GCD Subsequence
ユーザー rlangevinrlangevin
提出日時 2024-04-13 16:53:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,486 ms / 4,000 ms
コード長 956 bytes
コンパイル時間 327 ms
コンパイル使用メモリ 82,384 KB
実行使用メモリ 204,144 KB
最終ジャッジ日時 2024-04-13 16:54:02
合計ジャッジ時間 21,383 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,016 KB
testcase_01 AC 37 ms
53,260 KB
testcase_02 AC 36 ms
53,116 KB
testcase_03 AC 38 ms
53,396 KB
testcase_04 AC 36 ms
54,024 KB
testcase_05 AC 38 ms
54,060 KB
testcase_06 AC 39 ms
53,256 KB
testcase_07 AC 37 ms
54,196 KB
testcase_08 AC 965 ms
181,740 KB
testcase_09 AC 1,486 ms
204,144 KB
testcase_10 AC 918 ms
183,932 KB
testcase_11 AC 1,177 ms
195,704 KB
testcase_12 AC 1,096 ms
188,436 KB
testcase_13 AC 782 ms
177,324 KB
testcase_14 AC 1,153 ms
194,516 KB
testcase_15 AC 918 ms
179,548 KB
testcase_16 AC 904 ms
182,208 KB
testcase_17 AC 1,313 ms
203,896 KB
testcase_18 AC 785 ms
157,676 KB
testcase_19 AC 698 ms
157,616 KB
testcase_20 AC 792 ms
157,448 KB
testcase_21 AC 698 ms
157,688 KB
testcase_22 AC 771 ms
157,580 KB
testcase_23 AC 705 ms
157,640 KB
testcase_24 AC 787 ms
157,624 KB
testcase_25 AC 707 ms
157,880 KB
testcase_26 AC 777 ms
157,368 KB
testcase_27 AC 709 ms
157,532 KB
testcase_28 AC 618 ms
134,080 KB
testcase_29 AC 37 ms
52,576 KB
testcase_30 AC 37 ms
53,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import ceil, sqrt
def moebius_table(n):
    p = list(range(n + 1))
    for x in range(2, ceil(sqrt(n)) + 1):
        if p[x] == x:
            for y in range(x*x, n + 1, x):
                p[y] = x
            for y in range(x*x, n + 1, x*x):
                p[y] = 0
    res = [0] * (n + 1)
    res[1] = 1
    for x in range(2, n + 1):
        if p[x]:
            res[x] = -res[x//p[x]]

    return res


N = int(input())
A = list(map(int, input().split()))
M = max(A) + 5
dp = [0] * M
g = [0] * M
S = [0] * M
for a in A:
    S[a] = 1
s = 0
mod = 998244353
d = [[] for i in range(M)]
for i in range(1, M):
    for j in range(i, M, i):
        if S[j]:
            d[j].append(i)

m = moebius_table(M)

for a in A:
    temp = 0
    for dd in d[a]:
        temp += m[dd] * g[dd]
    v = 1 + s - temp
    s += v
    dp[a] += v
    s %= mod
    dp[a] %= mod
    for dd in d[a]:
        g[dd] += v
        g[dd] %= mod
        
print(sum(dp) % mod)
0