結果

問題 No.2075 GCD Subsequence
ユーザー rlangevinrlangevin
提出日時 2024-04-13 16:51:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,186 ms / 4,000 ms
コード長 932 bytes
コンパイル時間 363 ms
コンパイル使用メモリ 82,252 KB
実行使用メモリ 201,040 KB
最終ジャッジ日時 2024-04-13 16:51:52
合計ジャッジ時間 32,812 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,392 KB
testcase_01 AC 37 ms
53,700 KB
testcase_02 AC 36 ms
53,820 KB
testcase_03 AC 38 ms
53,132 KB
testcase_04 AC 56 ms
53,016 KB
testcase_05 AC 71 ms
52,828 KB
testcase_06 AC 39 ms
53,152 KB
testcase_07 AC 38 ms
53,392 KB
testcase_08 AC 1,537 ms
177,052 KB
testcase_09 AC 2,186 ms
201,040 KB
testcase_10 AC 1,595 ms
178,792 KB
testcase_11 AC 1,900 ms
191,456 KB
testcase_12 AC 1,699 ms
184,020 KB
testcase_13 AC 1,356 ms
172,296 KB
testcase_14 AC 1,960 ms
190,252 KB
testcase_15 AC 1,451 ms
174,520 KB
testcase_16 AC 1,494 ms
177,248 KB
testcase_17 AC 2,015 ms
200,968 KB
testcase_18 AC 1,118 ms
150,236 KB
testcase_19 AC 1,051 ms
150,420 KB
testcase_20 AC 1,138 ms
150,452 KB
testcase_21 AC 1,097 ms
150,200 KB
testcase_22 AC 1,131 ms
150,316 KB
testcase_23 AC 1,055 ms
150,296 KB
testcase_24 AC 1,131 ms
150,200 KB
testcase_25 AC 1,128 ms
150,396 KB
testcase_26 AC 1,096 ms
150,392 KB
testcase_27 AC 1,083 ms
150,100 KB
testcase_28 AC 713 ms
128,284 KB
testcase_29 AC 36 ms
53,480 KB
testcase_30 AC 36 ms
53,152 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()))
S = set(A)
M = max(A) + 5
dp = [0] * M
g = [0] * M
s = 0
mod = 998244353
d = [[] for i in range(M)]
for i in range(1, M):
    for j in range(i, M, i):
        if j in S:
            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