結果
| 問題 | No.2075 GCD Subsequence |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-09-17 14:43:09 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 1,816 ms / 4,000 ms |
| コード長 | 1,050 bytes |
| コンパイル時間 | 219 ms |
| コンパイル使用メモリ | 82,432 KB |
| 実行使用メモリ | 114,664 KB |
| 最終ジャッジ日時 | 2024-12-22 00:49:01 |
| 合計ジャッジ時間 | 29,251 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 28 |
ソースコード
n = int(input())
a = list(map(int,input().split()))
mod = 998244353
def e(n): #O(NloglogN)
l = [i for i in range(n+1)]
l[0] = 0
l[1] = 1
for i in range(2,n):
if l[i] == i:
for p in range(i+i,n+1,i):
l[p] = i
return l
l = e(10**6+10)
now = [0]*(10**6+10)
for ai in a[::-1]:
s = set()
aai = ai
while aai != 1:
s.add(l[aai])
aai //= l[aai]
s = list(s)
cnt = len(s)
tmp = 0
for bit in range(1,1<<cnt):
use = 1
c = 0
for i in range(cnt):
if (bit>>i) & 1:
use *= s[i]
c += 1
if c % 2 == 1:
tmp += now[use]
else:
tmp -= now[use]
for bit in range(1,1<<cnt):
use = 1
c = 0
for i in range(cnt):
if (bit>>i) & 1:
use *= s[i]
c += 1
now[use] += tmp + 1
now[use] %= mod
ans = 0
for i in range(1, 10**6+10):
s = set()
ii = i
while ii != 1:
s.add(l[ii])
ii //= l[ii]
c = len(s)
if c % 2 == 0:
ans -= now[i]
else:
ans += now[i]
ans %= mod
print((ans + a.count(1))%mod)