結果

問題 No.2313 Product of Subsequence (hard)
ユーザー sotanishysotanishy
提出日時 2023-05-24 21:40:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 3,489 ms / 4,000 ms
コード長 833 bytes
コンパイル時間 656 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 138,056 KB
最終ジャッジ日時 2024-07-21 11:13:36
合計ジャッジ時間 36,734 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
52,096 KB
testcase_01 AC 48 ms
52,480 KB
testcase_02 AC 50 ms
52,352 KB
testcase_03 AC 61 ms
61,312 KB
testcase_04 AC 64 ms
61,312 KB
testcase_05 AC 67 ms
62,464 KB
testcase_06 AC 62 ms
61,440 KB
testcase_07 AC 64 ms
61,568 KB
testcase_08 AC 313 ms
124,804 KB
testcase_09 AC 178 ms
94,976 KB
testcase_10 AC 303 ms
134,180 KB
testcase_11 AC 146 ms
93,568 KB
testcase_12 AC 290 ms
126,592 KB
testcase_13 AC 3,478 ms
134,144 KB
testcase_14 AC 3,455 ms
134,528 KB
testcase_15 AC 3,467 ms
134,144 KB
testcase_16 AC 3,489 ms
134,528 KB
testcase_17 AC 3,342 ms
134,272 KB
testcase_18 AC 3,340 ms
134,272 KB
testcase_19 AC 3,414 ms
134,528 KB
testcase_20 AC 3,321 ms
134,528 KB
testcase_21 AC 49 ms
57,600 KB
testcase_22 AC 42 ms
52,224 KB
testcase_23 AC 42 ms
52,224 KB
testcase_24 AC 42 ms
51,712 KB
testcase_25 AC 137 ms
120,328 KB
testcase_26 AC 112 ms
100,784 KB
testcase_27 AC 3,125 ms
138,056 KB
testcase_28 AC 254 ms
132,096 KB
testcase_29 AC 290 ms
131,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd
import sys
input = sys.stdin.readline


def divisor(n):
    divisors = []
    i = 1
    while i * i < n:
        if n % i == 0:
            divisors.append(i)
            divisors.append(n // i)
        i += 1
    if i * i == n:
        divisors.append(i)
    divisors.sort()
    return divisors


mod = 998244353
N, K = map(int, input().split())
A = list(map(int, input().split()))

if K == 1:
    print((pow(2, N, mod) - 1) % mod)
    exit()

div = divisor(K)
idx = {d: i for i, d in enumerate(div)}
D = len(div)

prod_idx = [[0]*D for _ in range(D)]
for i in range(D):
    for j in range(D):
        prod_idx[i][j] = idx[gcd(div[i]*div[j], K)]

dp = [0]*D
dp[0] = 1

for x in A:
    i = idx[gcd(x, K)]

    for j in range(D)[::-1]:
        k = prod_idx[i][j]
        dp[k] = (dp[k]+dp[j]) % mod
print(dp[-1])
0