結果

問題 No.1731 Product of Subsequence
ユーザー HydruHydru
提出日時 2021-11-06 13:36:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 891 ms / 2,000 ms
コード長 592 bytes
コンパイル時間 211 ms
コンパイル使用メモリ 82,472 KB
実行使用メモリ 165,968 KB
最終ジャッジ日時 2024-04-25 17:40:56
合計ジャッジ時間 10,551 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 806 ms
165,968 KB
testcase_01 AC 38 ms
54,060 KB
testcase_02 AC 40 ms
54,804 KB
testcase_03 AC 38 ms
54,472 KB
testcase_04 AC 38 ms
55,196 KB
testcase_05 AC 48 ms
63,404 KB
testcase_06 AC 41 ms
55,476 KB
testcase_07 AC 39 ms
55,460 KB
testcase_08 AC 92 ms
77,836 KB
testcase_09 AC 39 ms
55,396 KB
testcase_10 AC 891 ms
161,756 KB
testcase_11 AC 753 ms
149,736 KB
testcase_12 AC 46 ms
62,944 KB
testcase_13 AC 87 ms
78,548 KB
testcase_14 AC 663 ms
142,308 KB
testcase_15 AC 40 ms
53,932 KB
testcase_16 AC 39 ms
54,448 KB
testcase_17 AC 38 ms
55,320 KB
testcase_18 AC 757 ms
155,640 KB
testcase_19 AC 95 ms
78,072 KB
testcase_20 AC 657 ms
144,148 KB
testcase_21 AC 830 ms
156,996 KB
testcase_22 AC 62 ms
71,704 KB
testcase_23 AC 39 ms
54,368 KB
testcase_24 AC 82 ms
78,284 KB
testcase_25 AC 73 ms
75,740 KB
testcase_26 AC 188 ms
88,648 KB
testcase_27 AC 235 ms
92,864 KB
testcase_28 AC 423 ms
108,756 KB
testcase_29 AC 205 ms
88,336 KB
testcase_30 AC 872 ms
165,856 KB
testcase_31 AC 62 ms
71,492 KB
testcase_32 AC 39 ms
55,056 KB
testcase_33 AC 62 ms
71,372 KB
testcase_34 AC 115 ms
77,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import exit
from math import gcd
from collections import defaultdict
mod=10**9+7
n,k=map(int,input().split())
if k==1:
    print(pow(2,n,mod)-1)
    exit()

A=list(map(lambda x:gcd(int(x),k),input().split()))
B=[]
cnt=0
for x in A:
    if x==1:
        cnt+=1
    else:
        B.append(x)

m=len(B)
dp=[defaultdict(int) for _ in range(m+1)]
dp[0][1]=1
for i in range(1,m+1):
    for j in dp[i-1]:
        dp[i][j]+=dp[i-1][j]
        dp[i][j]%=mod

        ai=B[i-1]
        g=gcd(j*ai,k)
        dp[i][g]+=dp[i-1][j]
        dp[i][g]%=mod
ans=dp[m][k]*pow(2,cnt,mod)%mod
print(ans)
0