結果

問題 No.1731 Product of Subsequence
ユーザー roarisroaris
提出日時 2021-11-05 22:20:36
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 1,060 ms / 2,000 ms
コード長 809 bytes
コンパイル時間 460 ms
コンパイル使用メモリ 87,316 KB
実行使用メモリ 80,080 KB
最終ジャッジ日時 2023-08-07 23:14:21
合計ジャッジ時間 14,148 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 803 ms
79,972 KB
testcase_01 AC 95 ms
72,180 KB
testcase_02 AC 92 ms
72,028 KB
testcase_03 AC 99 ms
77,304 KB
testcase_04 AC 92 ms
72,400 KB
testcase_05 AC 104 ms
78,280 KB
testcase_06 AC 103 ms
77,652 KB
testcase_07 AC 98 ms
77,148 KB
testcase_08 AC 141 ms
78,160 KB
testcase_09 AC 98 ms
76,792 KB
testcase_10 AC 1,060 ms
80,008 KB
testcase_11 AC 902 ms
79,696 KB
testcase_12 AC 107 ms
78,376 KB
testcase_13 AC 132 ms
78,872 KB
testcase_14 AC 824 ms
79,296 KB
testcase_15 AC 93 ms
72,020 KB
testcase_16 AC 92 ms
71,616 KB
testcase_17 AC 91 ms
71,992 KB
testcase_18 AC 872 ms
79,848 KB
testcase_19 AC 128 ms
78,656 KB
testcase_20 AC 724 ms
79,692 KB
testcase_21 AC 1,059 ms
80,028 KB
testcase_22 AC 325 ms
79,072 KB
testcase_23 AC 98 ms
76,988 KB
testcase_24 AC 123 ms
78,504 KB
testcase_25 AC 113 ms
78,476 KB
testcase_26 AC 275 ms
78,672 KB
testcase_27 AC 334 ms
78,768 KB
testcase_28 AC 563 ms
79,008 KB
testcase_29 AC 304 ms
78,764 KB
testcase_30 AC 718 ms
80,080 KB
testcase_31 AC 330 ms
79,216 KB
testcase_32 AC 102 ms
77,048 KB
testcase_33 AC 126 ms
78,568 KB
testcase_34 AC 192 ms
78,788 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from collections import *
from math import gcd

N, K = map(int, input().split())
A = list(map(int, input().split()))
MOD = 10**9+7

if K==1:
    exit(print((pow(2, N, MOD)-1)%MOD))
    
divs = []

for d in range(1, int(K**0.5)+1):
    if K%d==0:
        divs.append(d)
        
        if d!=K//d:
            divs.append(K//d)

divs.sort()
idx = defaultdict(int)

for i in range(len(divs)):
    idx[divs[i]] = i

M = len(idx.keys())
dp = [0]*M
dp[0] = 1

for i in range(N):
    ndp = [0]*M
    
    for j in range(M):
        ndp[j] += dp[j]
        ndp[j] %= MOD
        
        if divs[j]*A[i]%K==0:
            nj = M-1
        else:
            nj = idx[gcd(K, divs[j]*A[i])]
        
        ndp[nj] += dp[j]
        ndp[nj] %= MOD
    
    dp = ndp

print(dp[-1])
0