結果

問題 No.2075 GCD Subsequence
ユーザー terasaterasa
提出日時 2022-11-22 18:11:43
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,388 bytes
コンパイル時間 356 ms
コンパイル使用メモリ 81,776 KB
実行使用メモリ 119,304 KB
最終ジャッジ日時 2023-10-24 11:07:53
合計ジャッジ時間 11,277 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
78,500 KB
testcase_01 AC 91 ms
78,500 KB
testcase_02 AC 89 ms
78,500 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 92 ms
78,508 KB
testcase_30 AC 102 ms
78,508 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0