結果

問題 No.1731 Product of Subsequence
ユーザー ああいいああいい
提出日時 2022-03-16 17:39:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 840 ms / 2,000 ms
コード長 532 bytes
コンパイル時間 281 ms
コンパイル使用メモリ 82,392 KB
実行使用メモリ 87,596 KB
最終ジャッジ日時 2024-04-25 17:58:11
合計ジャッジ時間 9,715 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 703 ms
84,648 KB
testcase_01 AC 38 ms
54,200 KB
testcase_02 AC 38 ms
55,104 KB
testcase_03 AC 38 ms
54,412 KB
testcase_04 AC 38 ms
55,688 KB
testcase_05 AC 51 ms
65,036 KB
testcase_06 AC 48 ms
64,808 KB
testcase_07 AC 40 ms
60,456 KB
testcase_08 AC 86 ms
76,584 KB
testcase_09 AC 41 ms
60,912 KB
testcase_10 AC 828 ms
87,320 KB
testcase_11 AC 711 ms
84,540 KB
testcase_12 AC 57 ms
72,004 KB
testcase_13 AC 82 ms
76,772 KB
testcase_14 AC 617 ms
83,288 KB
testcase_15 AC 37 ms
54,132 KB
testcase_16 AC 33 ms
52,468 KB
testcase_17 AC 37 ms
54,824 KB
testcase_18 AC 678 ms
82,644 KB
testcase_19 AC 81 ms
77,180 KB
testcase_20 AC 556 ms
80,680 KB
testcase_21 AC 840 ms
87,596 KB
testcase_22 AC 65 ms
72,016 KB
testcase_23 AC 39 ms
59,760 KB
testcase_24 AC 85 ms
77,012 KB
testcase_25 AC 77 ms
77,016 KB
testcase_26 AC 181 ms
77,456 KB
testcase_27 AC 238 ms
77,148 KB
testcase_28 AC 402 ms
79,048 KB
testcase_29 AC 191 ms
77,408 KB
testcase_30 AC 658 ms
83,788 KB
testcase_31 AC 63 ms
72,076 KB
testcase_32 AC 40 ms
60,224 KB
testcase_33 AC 65 ms
71,796 KB
testcase_34 AC 122 ms
76,964 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

def gcd(a,b):
    while True:
        r = a % b
        a = b
        b = r
        if r == 0:return a
A = [gcd(a,K) for a in A]
P = 10 ** 9 + 7

import sys
if K == 1:
    print((pow(2,N,P)-1)%P)
    exit()
from collections import defaultdict
dp = defaultdict(int)
dp[1] = 1
for a in A:
    nx = defaultdict(int)
    for i in dp:
        nx[gcd(i * a,K)] += dp[i]
    for k in dp:
        nx[k] += dp[k]
    for k in nx:
        nx[k] %= P
    dp = nx
print(dp[K])
0