結果

問題 No.1731 Product of Subsequence
ユーザー 👑 KazunKazun
提出日時 2021-11-05 22:05:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,948 ms / 2,000 ms
コード長 1,168 bytes
コンパイル時間 219 ms
コンパイル使用メモリ 82,944 KB
実行使用メモリ 87,808 KB
最終ジャッジ日時 2024-04-24 05:53:32
合計ジャッジ時間 20,208 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,825 ms
86,016 KB
testcase_01 AC 37 ms
52,352 KB
testcase_02 AC 37 ms
52,352 KB
testcase_03 AC 41 ms
57,856 KB
testcase_04 AC 37 ms
52,736 KB
testcase_05 AC 60 ms
65,664 KB
testcase_06 AC 52 ms
63,104 KB
testcase_07 AC 42 ms
58,240 KB
testcase_08 AC 119 ms
76,672 KB
testcase_09 AC 41 ms
58,496 KB
testcase_10 AC 1,877 ms
87,808 KB
testcase_11 AC 1,583 ms
85,248 KB
testcase_12 AC 57 ms
67,328 KB
testcase_13 AC 96 ms
76,672 KB
testcase_14 AC 1,629 ms
83,328 KB
testcase_15 AC 39 ms
52,352 KB
testcase_16 AC 39 ms
52,096 KB
testcase_17 AC 40 ms
52,224 KB
testcase_18 AC 1,454 ms
82,176 KB
testcase_19 AC 101 ms
76,800 KB
testcase_20 AC 1,185 ms
80,768 KB
testcase_21 AC 1,862 ms
87,552 KB
testcase_22 AC 74 ms
74,752 KB
testcase_23 AC 42 ms
58,880 KB
testcase_24 AC 100 ms
76,672 KB
testcase_25 AC 82 ms
76,544 KB
testcase_26 AC 342 ms
77,056 KB
testcase_27 AC 472 ms
77,312 KB
testcase_28 AC 931 ms
78,848 KB
testcase_29 AC 343 ms
76,928 KB
testcase_30 AC 1,948 ms
87,168 KB
testcase_31 AC 69 ms
73,344 KB
testcase_32 AC 41 ms
58,496 KB
testcase_33 AC 68 ms
72,832 KB
testcase_34 AC 148 ms
76,672 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#素因数分解
def Prime_Factorization(N):
    if N<0:
        R=[[-1,1]]
    else:
        R=[]

    N=abs(N)

    if N&1==0:
        C=0
        while N&1==0:
            N>>=1
            C+=1
        R.append([2,C])

    if N%3==0:
        C=0
        while N%3==0:
            N//=3
            C+=1
        R.append([3,C])

    k=5
    Flag=0
    while k*k<=N:
        if N%k==0:
            C=0
            while N%k==0:
                C+=1
                N//=k
            R.append([k,C])
        k+=2+2*Flag
        Flag^=1

    if N!=1:
        R.append([N,1])

    return R
#==================================================
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))

P=[(p,e) for p,e in Prime_Factorization(K)]

m=len(P)
DP={(0,)*m:1}
v=[0]*m

for a in A:
    E=DP.copy()

    f=[0]*m
    for i in range(m):
        p,_=P[i]
        while a%p==0:
            f[i]+=1
            a//=p

    for u in E:
        for i in range(m):
            v[i]=min(u[i]+f[i],P[i][1])
        DP[tuple(v)]=(DP.get(tuple(v),0)+E[u])%Mod

end=tuple([e for p,e in P])
print(DP.get(end,0))
0