結果

問題 No.1731 Product of Subsequence
ユーザー Hydru
提出日時 2021-11-06 14:44:39
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 814 bytes
コンパイル時間 161 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 66,944 KB
最終ジャッジ日時 2024-11-07 11:13:37
合計ジャッジ時間 5,515 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 12 WA * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import exit
from math import gcd
mod = 10**9+7

def factors(a):
    if a <= 0: return [0]
    dd0, dd1 = [], []
    for d in range(1, round(a**0.5)+1):
        if a%d: continue
        dd0.append(d)
        dd1.append(a//d)
    if dd0[-1] == dd1[-1]: dd1.pop()
    return dd0+dd1[::-1]

n,k=map(int,input().split())
A=list(map(lambda x:gcd(int(x),k),input().split()))
if k == 1:
    print(pow(2,n,mod)-1)
    exit()

factor = factors(k)
ftoj = {f: j for j, f in enumerate(factor)}

fn = len(factor)
dp = [0]*fn
dp[0] = 1
cnt=0
B=[]
for x in A:
    if x==1:
        cnt+=1
    else:
        B.append(x)
for b in B:
    for j in range(fn)[::-1]:
        pre = dp[j]
        if pre == 0: continue
        g = gcd(b*factor[j], k)
        nj = ftoj[g]
        dp[nj] += pre
        dp[nj] %= mod

print(dp[-1])
0