結果
| 問題 |
No.1731 Product of Subsequence
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-11-05 21:51:29 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,063 bytes |
| コンパイル時間 | 337 ms |
| コンパイル使用メモリ | 82,156 KB |
| 実行使用メモリ | 82,768 KB |
| 最終ジャッジ日時 | 2024-11-06 12:38:47 |
| 合計ジャッジ時間 | 21,941 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 28 TLE * 3 |
ソースコード
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))