結果

問題 No.1731 Product of Subsequence
ユーザー ああいい
提出日時 2022-03-16 17:39:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 984 ms / 2,000 ms
コード長 532 bytes
コンパイル時間 350 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 87,680 KB
最終ジャッジ日時 2024-11-08 05:21:07
合計ジャッジ時間 11,719 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

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