結果

問題 No.1731 Product of Subsequence
ユーザー HydruHydru
提出日時 2021-11-06 14:44:39
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 814 bytes
コンパイル時間 173 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 66,688 KB
最終ジャッジ日時 2024-04-25 01:46:04
合計ジャッジ時間 5,490 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 39 ms
52,608 KB
testcase_02 AC 40 ms
52,736 KB
testcase_03 AC 42 ms
57,984 KB
testcase_04 AC 40 ms
52,608 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 43 ms
57,984 KB
testcase_08 WA -
testcase_09 AC 45 ms
59,520 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 48 ms
60,416 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 43 ms
52,864 KB
testcase_16 AC 39 ms
52,352 KB
testcase_17 AC 39 ms
52,736 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 240 ms
65,920 KB
testcase_21 WA -
testcase_22 AC 64 ms
66,304 KB
testcase_23 AC 43 ms
59,264 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 63 ms
66,048 KB
testcase_32 AC 43 ms
59,392 KB
testcase_33 AC 58 ms
64,512 KB
testcase_34 WA -
権限があれば一括ダウンロードができます

ソースコード

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