結果

問題 No.2313 Product of Subsequence (hard)
ユーザー convexineq
提出日時 2023-05-25 10:59:59
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 951 ms / 4,000 ms
コード長 769 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,008 ms
コンパイル使用メモリ 84,992 KB
実行使用メモリ 150,812 KB
最終ジャッジ日時 2026-05-30 02:07:20
合計ジャッジ時間 12,797 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
readline = sys.stdin.readline

n,k = map(int,readline().split())
*a, = map(int,readline().split())

MOD = 998244353

from math import gcd
from collections import defaultdict

da = defaultdict(int)
for ai in a:
    da[gcd(ai,k)] += 1

def get(ai,num):
    d = defaultdict(int)
    d[1] = 1
    for _ in range(num):
        nd = d.copy()
        for r,v in d.items():
            nr = gcd(ai*r,k)
            nd[nr] += v
            nd[nr] %= MOD
        d = nd
    return d


d = defaultdict(int)
d[1] = 1
for ai,num in da.items():
    nd = defaultdict(int)
    for r,v in get(ai,num).items():
        for rr,vv in d.items():
            nr = gcd(r*rr,k)
            nd[nr] += v*vv
            nd[nr] %= MOD
    d = nd

ans = d[k] - int(k==1)
print(ans%MOD)

0