結果

問題 No.1731 Product of Subsequence
ユーザー roarisroaris
提出日時 2021-11-05 22:20:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,015 ms / 2,000 ms
コード長 809 bytes
コンパイル時間 390 ms
コンパイル使用メモリ 82,412 KB
実行使用メモリ 78,616 KB
最終ジャッジ日時 2024-04-25 17:27:34
合計ジャッジ時間 11,509 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 723 ms
78,072 KB
testcase_01 AC 39 ms
54,868 KB
testcase_02 AC 38 ms
54,912 KB
testcase_03 AC 38 ms
60,036 KB
testcase_04 AC 37 ms
55,196 KB
testcase_05 AC 44 ms
63,732 KB
testcase_06 AC 42 ms
62,200 KB
testcase_07 AC 39 ms
61,404 KB
testcase_08 AC 78 ms
68,320 KB
testcase_09 AC 42 ms
60,656 KB
testcase_10 AC 1,012 ms
78,616 KB
testcase_11 AC 858 ms
78,008 KB
testcase_12 AC 48 ms
65,636 KB
testcase_13 AC 80 ms
77,016 KB
testcase_14 AC 763 ms
77,532 KB
testcase_15 AC 36 ms
55,348 KB
testcase_16 AC 35 ms
55,168 KB
testcase_17 AC 38 ms
55,312 KB
testcase_18 AC 820 ms
78,216 KB
testcase_19 AC 73 ms
76,928 KB
testcase_20 AC 696 ms
77,852 KB
testcase_21 AC 1,015 ms
78,356 KB
testcase_22 AC 248 ms
77,400 KB
testcase_23 AC 40 ms
61,584 KB
testcase_24 AC 62 ms
67,064 KB
testcase_25 AC 56 ms
67,432 KB
testcase_26 AC 225 ms
76,976 KB
testcase_27 AC 288 ms
77,064 KB
testcase_28 AC 499 ms
77,284 KB
testcase_29 AC 244 ms
77,140 KB
testcase_30 AC 661 ms
77,860 KB
testcase_31 AC 265 ms
77,440 KB
testcase_32 AC 41 ms
61,068 KB
testcase_33 AC 72 ms
77,160 KB
testcase_34 AC 133 ms
77,132 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