結果

問題 No.1731 Product of Subsequence
ユーザー とりゐとりゐ
提出日時 2021-10-18 03:43:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,096 ms / 2,000 ms
コード長 584 bytes
コンパイル時間 340 ms
コンパイル使用メモリ 82,164 KB
実行使用メモリ 179,372 KB
最終ジャッジ日時 2024-04-25 17:09:05
合計ジャッジ時間 12,565 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 974 ms
174,788 KB
testcase_01 AC 42 ms
55,872 KB
testcase_02 AC 43 ms
54,744 KB
testcase_03 AC 42 ms
55,756 KB
testcase_04 AC 41 ms
54,476 KB
testcase_05 AC 54 ms
64,400 KB
testcase_06 AC 56 ms
64,576 KB
testcase_07 AC 42 ms
55,476 KB
testcase_08 AC 100 ms
77,724 KB
testcase_09 AC 60 ms
68,056 KB
testcase_10 AC 1,096 ms
174,992 KB
testcase_11 AC 907 ms
167,720 KB
testcase_12 AC 60 ms
68,200 KB
testcase_13 AC 109 ms
78,232 KB
testcase_14 AC 813 ms
156,484 KB
testcase_15 AC 42 ms
55,512 KB
testcase_16 AC 42 ms
53,924 KB
testcase_17 AC 41 ms
55,152 KB
testcase_18 AC 810 ms
156,004 KB
testcase_19 AC 102 ms
78,088 KB
testcase_20 AC 673 ms
144,532 KB
testcase_21 AC 1,078 ms
179,372 KB
testcase_22 AC 63 ms
70,624 KB
testcase_23 AC 60 ms
68,228 KB
testcase_24 AC 95 ms
78,404 KB
testcase_25 AC 87 ms
78,752 KB
testcase_26 AC 245 ms
94,440 KB
testcase_27 AC 304 ms
98,416 KB
testcase_28 AC 515 ms
118,132 KB
testcase_29 AC 257 ms
94,276 KB
testcase_30 AC 1,029 ms
174,872 KB
testcase_31 AC 64 ms
69,364 KB
testcase_32 AC 58 ms
67,564 KB
testcase_33 AC 64 ms
69,244 KB
testcase_34 AC 149 ms
83,604 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=gcd(a[i-1],k)
  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