結果

問題 No.1731 Product of Subsequence
ユーザー roaris
提出日時 2021-11-05 22:18:23
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 754 bytes
コンパイル時間 434 ms
コンパイル使用メモリ 82,308 KB
実行使用メモリ 78,196 KB
最終ジャッジ日時 2024-11-06 13:12:29
合計ジャッジ時間 12,606 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 27 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

for d in range(1, int(K**0.5)+1):
    if K%d==0:
        divs.append(d)
        
        if d!=K//d:
            divs.append(K//d)

divs.sort()
idx = defaultdict(int)

for i in range(len(divs)):
    idx[divs[i]] = i

M = len(idx.keys())
dp = [0]*M
dp[0] = 1
MOD = 10**9+7

for i in range(N):
    ndp = [0]*M
    
    for j in range(M):
        ndp[j] += dp[j]
        ndp[j] %= MOD
        
        if divs[j]*A[i]%K==0:
            nj = M-1
        else:
            nj = idx[gcd(K, divs[j]*A[i])]
        
        ndp[nj] += dp[j]
        ndp[nj] %= MOD
    
    dp = ndp

print(dp[-1])
0