結果

問題 No.1731 Product of Subsequence
ユーザー HydruHydru
提出日時 2021-11-06 14:45:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 297 ms / 2,000 ms
コード長 833 bytes
コンパイル時間 242 ms
コンパイル使用メモリ 82,436 KB
実行使用メモリ 67,524 KB
最終ジャッジ日時 2024-04-25 17:41:20
合計ジャッジ時間 4,963 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 294 ms
67,248 KB
testcase_01 AC 37 ms
53,104 KB
testcase_02 AC 38 ms
53,232 KB
testcase_03 AC 40 ms
58,944 KB
testcase_04 AC 37 ms
53,044 KB
testcase_05 AC 41 ms
60,408 KB
testcase_06 AC 38 ms
54,336 KB
testcase_07 AC 38 ms
58,480 KB
testcase_08 AC 55 ms
63,400 KB
testcase_09 AC 41 ms
60,480 KB
testcase_10 AC 284 ms
66,612 KB
testcase_11 AC 245 ms
66,656 KB
testcase_12 AC 43 ms
61,884 KB
testcase_13 AC 50 ms
65,096 KB
testcase_14 AC 229 ms
66,348 KB
testcase_15 AC 34 ms
53,004 KB
testcase_16 AC 36 ms
52,952 KB
testcase_17 AC 36 ms
54,148 KB
testcase_18 AC 269 ms
67,040 KB
testcase_19 AC 51 ms
64,472 KB
testcase_20 AC 228 ms
67,524 KB
testcase_21 AC 285 ms
67,356 KB
testcase_22 AC 60 ms
67,052 KB
testcase_23 AC 40 ms
60,148 KB
testcase_24 AC 51 ms
65,092 KB
testcase_25 AC 49 ms
65,312 KB
testcase_26 AC 79 ms
66,024 KB
testcase_27 AC 94 ms
66,208 KB
testcase_28 AC 166 ms
64,968 KB
testcase_29 AC 82 ms
64,848 KB
testcase_30 AC 297 ms
66,596 KB
testcase_31 AC 60 ms
66,364 KB
testcase_32 AC 39 ms
59,652 KB
testcase_33 AC 49 ms
65,456 KB
testcase_34 AC 53 ms
64,736 KB
権限があれば一括ダウンロードができます

ソースコード

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]*pow(2,cnt,mod)%mod)
0