結果

問題 No.1731 Product of Subsequence
ユーザー とりゐとりゐ
提出日時 2021-10-10 22:51:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,739 ms / 2,000 ms
コード長 577 bytes
コンパイル時間 189 ms
コンパイル使用メモリ 82,260 KB
実行使用メモリ 179,516 KB
最終ジャッジ日時 2024-04-25 17:08:50
合計ジャッジ時間 17,792 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,455 ms
175,512 KB
testcase_01 AC 42 ms
55,192 KB
testcase_02 AC 41 ms
54,460 KB
testcase_03 AC 41 ms
55,700 KB
testcase_04 AC 42 ms
54,872 KB
testcase_05 AC 52 ms
63,936 KB
testcase_06 AC 55 ms
65,428 KB
testcase_07 AC 42 ms
56,652 KB
testcase_08 AC 105 ms
78,140 KB
testcase_09 AC 58 ms
67,064 KB
testcase_10 AC 1,739 ms
178,480 KB
testcase_11 AC 1,454 ms
169,212 KB
testcase_12 AC 58 ms
67,220 KB
testcase_13 AC 139 ms
79,428 KB
testcase_14 AC 1,289 ms
159,384 KB
testcase_15 AC 41 ms
54,780 KB
testcase_16 AC 41 ms
55,060 KB
testcase_17 AC 42 ms
54,656 KB
testcase_18 AC 1,200 ms
158,012 KB
testcase_19 AC 137 ms
79,304 KB
testcase_20 AC 1,001 ms
145,828 KB
testcase_21 AC 1,725 ms
179,516 KB
testcase_22 AC 64 ms
71,268 KB
testcase_23 AC 58 ms
67,312 KB
testcase_24 AC 104 ms
78,404 KB
testcase_25 AC 91 ms
78,464 KB
testcase_26 AC 374 ms
96,436 KB
testcase_27 AC 473 ms
100,744 KB
testcase_28 AC 819 ms
120,500 KB
testcase_29 AC 399 ms
95,356 KB
testcase_30 AC 1,534 ms
178,080 KB
testcase_31 AC 63 ms
71,556 KB
testcase_32 AC 58 ms
67,508 KB
testcase_33 AC 64 ms
71,244 KB
testcase_34 AC 230 ms
84,916 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 解説用
from math import gcd
from collections import defaultdict

n,k=map(int,input().split())
a=list(map(int,input().split()))
mod=10**9+7
# dp を連想配列で管理
dp=[defaultdict(int) for i in range(n+1)]
# dp[0][1]=1,dp[0][j]=0 (j!=1)
dp[0][1]=1
for i in range(1,n+1):
  ai=a[i-1]
  for j in dp[i-1]:
    # A_i を使わない場合の遷移
    dp[i][j]+=dp[i-1][j]
    dp[i][j]%=mod
    
    # A_i を使う場合の遷移
    g=gcd(j*ai,k)
    dp[i][g]+=dp[i-1][j]
    dp[i][g]%=mod

ans=dp[n][k]
# k=1 のときは答えを 1 引く
if k==1:
  ans-=1
print(ans)
0