結果

問題 No.2075 GCD Subsequence
ユーザー rlangevinrlangevin
提出日時 2024-04-14 20:52:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,766 ms / 4,000 ms
コード長 1,044 bytes
コンパイル時間 314 ms
コンパイル使用メモリ 82,252 KB
実行使用メモリ 204,220 KB
最終ジャッジ日時 2024-04-14 20:52:48
合計ジャッジ時間 25,927 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
52,560 KB
testcase_01 AC 37 ms
52,716 KB
testcase_02 AC 36 ms
52,264 KB
testcase_03 AC 36 ms
53,428 KB
testcase_04 AC 59 ms
53,228 KB
testcase_05 AC 41 ms
53,264 KB
testcase_06 AC 36 ms
52,672 KB
testcase_07 AC 49 ms
53,552 KB
testcase_08 AC 1,086 ms
181,872 KB
testcase_09 AC 1,766 ms
204,220 KB
testcase_10 AC 1,168 ms
183,800 KB
testcase_11 AC 1,419 ms
195,712 KB
testcase_12 AC 1,304 ms
188,896 KB
testcase_13 AC 1,106 ms
177,568 KB
testcase_14 AC 1,455 ms
194,620 KB
testcase_15 AC 1,101 ms
179,508 KB
testcase_16 AC 1,041 ms
182,100 KB
testcase_17 AC 1,585 ms
203,792 KB
testcase_18 AC 916 ms
157,900 KB
testcase_19 AC 942 ms
157,904 KB
testcase_20 AC 862 ms
158,012 KB
testcase_21 AC 935 ms
157,932 KB
testcase_22 AC 925 ms
157,924 KB
testcase_23 AC 878 ms
157,828 KB
testcase_24 AC 940 ms
157,848 KB
testcase_25 AC 858 ms
158,092 KB
testcase_26 AC 904 ms
157,888 KB
testcase_27 AC 940 ms
157,944 KB
testcase_28 AC 715 ms
134,444 KB
testcase_29 AC 36 ms
52,772 KB
testcase_30 AC 36 ms
53,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class Mobius():
    def __init__(self, N):
        self.L = list(range(N + 1))
        self.mobius = [1] * (N + 1)
        for i in range(2, N + 1):
            if i != self.L[i]:
                continue
            self.mobius[i] = -1
            for j in range(2 * i, N + 1, i):
                if self.L[j] == j:
                    self.L[j] = i
                if (j // i) % i == 0:
                    self.mobius[j] = 0
                else:
                    self.mobius[j] = - self.mobius[j]


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 = Mobius(M).mobius

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