結果
| 問題 | No.1731 Product of Subsequence | 
| コンテスト | |
| ユーザー |  H20 | 
| 提出日時 | 2021-12-08 10:45:35 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 836 ms / 2,000 ms | 
| コード長 | 463 bytes | 
| コンパイル時間 | 445 ms | 
| コンパイル使用メモリ | 82,432 KB | 
| 実行使用メモリ | 80,640 KB | 
| 最終ジャッジ日時 | 2024-11-08 05:17:23 | 
| 合計ジャッジ時間 | 11,377 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 31 | 
ソースコード
import collections
import math
N,K = map(int,input().split())
A = list(map(int,input().split()))
mod = 10**9+7
for i in range(N):
    A[i] = math.gcd(A[i],K)
DP = collections.defaultdict(int)
DP[1]=1
for a in A:
    NDP = collections.defaultdict(int)
    CDP = DP.copy()
    for k,v in CDP.items():
        gcd = math.gcd(K,a*k)
        NDP[gcd]=(NDP[gcd]+DP[k])%mod
        NDP[k]=(NDP[k]+DP[k])%mod
    DP = NDP
if K==1:
    DP[K]=(DP[K]-1)%mod
print(DP[K])
            
            
            
        