結果
| 問題 |
No.2075 GCD Subsequence
|
| コンテスト | |
| ユーザー |
terasa
|
| 提出日時 | 2022-11-22 18:11:43 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,388 bytes |
| コンパイル時間 | 163 ms |
| コンパイル使用メモリ | 82,244 KB |
| 実行使用メモリ | 120,120 KB |
| 最終ジャッジ日時 | 2024-09-23 03:27:39 |
| 合計ジャッジ時間 | 9,934 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 2 WA * 26 |
ソースコード
from typing import List, Tuple, Callable, TypeVar
import sys
import itertools
import heapq
import bisect
import math
from collections import deque, defaultdict, Counter
from functools import lru_cache, cmp_to_key
input = sys.stdin.readline
if __file__ != 'prog.py':
sys.setrecursionlimit(10 ** 6)
def readints(): return map(int, input().split())
def readlist(): return list(readints())
def readstr(): return input()[:-1]
class Osa_k:
# N以下の整数を素因数分解 O(NlogN)
def __init__(self, N):
self.min_factor = [i for i in range(N + 1)]
for i in range(2, N + 1):
if i * i > N:
break
if self.min_factor[i] == i:
for j in range(2, N + 1):
if i * j > N:
break
if self.min_factor[i * j] > i:
self.min_factor[i * j] = i
def factors(self, n):
f = []
while n > 1:
f.append(self.min_factor[n])
n //= self.min_factor[n]
return f
N = int(input())
A = readlist()
mod = 998244353
osa_k = Osa_k(10 ** 6)
S = defaultdict(int)
ans = 0
for a in A:
acc = 1
factors = set(osa_k.factors(a))
for f in factors:
acc += S[f]
acc %= mod
for f in factors:
S[f] += acc
S[f] %= mod
ans += acc
ans %= mod
print(ans)
terasa