結果

問題 No.1731 Product of Subsequence
ユーザー Hydru
提出日時 2021-11-06 13:22:39
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 487 bytes
コンパイル時間 449 ms
コンパイル使用メモリ 81,792 KB
実行使用メモリ 180,116 KB
最終ジャッジ日時 2024-11-07 09:35:05
合計ジャッジ時間 13,976 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample RE * 4
other AC * 4 RE * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import exit
from math import gcd
from collections import defaultdict
mod=10**9+7
n,k=map(int,input().split())
if k==1:
    print(pow(2,n,mod)-1)
    exit()

A=list(map(lambda x:gcd(int(x),k),input().split()))
ans=0

dp=[defaultdict(int) for _ in range(n+1)]
dp[0][1]=1
for i in range(1,n+1):
    for j in dp[i-1]:
        dp[i][j]+=dp[i-1][j]
        dp[i][j]%=mod

        ai=A[i]
        g=gcd(j*ai,k)
        dp[i][g]+=dp[i-1][j]
        dp[i][g]%=mod
ans=dp[n][k]
print(ans)
0