結果
| 問題 |
No.2075 GCD Subsequence
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-04-16 16:25:48 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,484 bytes |
| コンパイル時間 | 482 ms |
| コンパイル使用メモリ | 82,032 KB |
| 実行使用メモリ | 138,600 KB |
| 最終ジャッジ日時 | 2025-04-16 16:27:48 |
| 合計ジャッジ時間 | 17,538 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 15 TLE * 8 -- * 5 |
ソースコード
import sys
from sys import stdin
from collections import defaultdict
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
input = sys.stdin.read().split()
n = int(input[0])
a = list(map(int, input[1:n+1]))
cnt = defaultdict(int)
answer = 0
for x in a:
if x == 1:
primes = []
else:
factors = set()
temp = x
while temp > 1:
p = spf[temp]
factors.add(p)
while temp % p == 0:
temp //= p
primes = list(factors)
k = len(primes)
S = 0
for mask in range(1, 1 << k):
bits = bin(mask).count('1')
product = 1
for i in range(k):
if mask & (1 << i):
product *= primes[i]
sign = (-1) ** (bits + 1)
S += sign * cnt.get(product, 0)
S %= MOD
new = (1 + S) % MOD
answer = (answer + new) % MOD
for mask in range(0, 1 << k):
product = 1
for i in range(k):
if mask & (1 << i):
product *= primes[i]
cnt[product] = (cnt[product] + new) % MOD
print(answer % MOD)
if __name__ == '__main__':
main()
lam6er