結果

問題 No.1731 Product of Subsequence
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2021-11-05 21:51:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,868 ms / 2,000 ms
コード長 1,063 bytes
コンパイル時間 259 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 82,688 KB
最終ジャッジ日時 2024-04-24 05:38:20
合計ジャッジ時間 20,024 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,787 ms
82,560 KB
testcase_01 AC 36 ms
52,096 KB
testcase_02 AC 37 ms
52,096 KB
testcase_03 AC 40 ms
57,856 KB
testcase_04 AC 36 ms
52,736 KB
testcase_05 AC 62 ms
68,096 KB
testcase_06 AC 50 ms
62,592 KB
testcase_07 AC 39 ms
58,240 KB
testcase_08 AC 131 ms
76,672 KB
testcase_09 AC 41 ms
58,368 KB
testcase_10 AC 1,842 ms
82,264 KB
testcase_11 AC 1,575 ms
80,384 KB
testcase_12 AC 55 ms
65,408 KB
testcase_13 AC 94 ms
77,056 KB
testcase_14 AC 1,435 ms
80,128 KB
testcase_15 AC 36 ms
52,224 KB
testcase_16 AC 36 ms
51,840 KB
testcase_17 AC 35 ms
52,480 KB
testcase_18 AC 1,622 ms
81,536 KB
testcase_19 AC 86 ms
76,544 KB
testcase_20 AC 1,279 ms
78,976 KB
testcase_21 AC 1,866 ms
82,048 KB
testcase_22 AC 76 ms
72,832 KB
testcase_23 AC 40 ms
58,752 KB
testcase_24 AC 108 ms
77,056 KB
testcase_25 AC 94 ms
76,800 KB
testcase_26 AC 368 ms
77,056 KB
testcase_27 AC 440 ms
77,184 KB
testcase_28 AC 852 ms
77,696 KB
testcase_29 AC 366 ms
77,184 KB
testcase_30 AC 1,868 ms
82,688 KB
testcase_31 AC 74 ms
71,040 KB
testcase_32 AC 42 ms
58,112 KB
testcase_33 AC 72 ms
70,912 KB
testcase_34 AC 188 ms
76,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,k = map(int,input().split())
A = list(map(int,input().split()))
mod = 10**9+7
if k == 1:
    print((pow(2,n,mod)-1)%mod)
    exit()
div = []
dnum = []
num = k

for i in range(2,int(k**0.5)+1):
    if num%i:
        continue
    count = 0
    while num%i == 0:
        num //= i
        count += 1
    div.append(i)
    dnum.append(count)
if num != 1:
    div.append(num)
    dnum.append(1)
l = len(div)
dic = {1:1}
for a in A:
    cand = [0]*l
    for i,d in enumerate(div):
        while a%d == 0:
            a //= d
            cand[i] += 1
    ndic = {}
    for x,v in dic.items():
        num = x
        cand2 = [0]*l
        for i,d in enumerate(div):
            while num%d == 0:
                num //= d
                cand2[i] += 1
        nex = 1
        for i,d in enumerate(div):
            if cand[i]+cand2[i] > dnum[i]:
                nex *= pow(d,dnum[i])
            else:
                nex *= pow(d,cand[i]+cand2[i])
        ndic[nex] = (ndic.get(nex,0)+v)%mod
        ndic[x] = (ndic.get(x,0)+v)%mod
    dic = ndic

print(dic.get(k,0))
0