結果

問題 No.368 LCM of K-products
ユーザー lloyzlloyz
提出日時 2024-01-03 00:28:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 584 ms / 2,000 ms
コード長 988 bytes
コンパイル時間 2,777 ms
コンパイル使用メモリ 81,444 KB
実行使用メモリ 76,612 KB
最終ジャッジ日時 2024-01-03 00:28:51
合計ジャッジ時間 7,534 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
76,612 KB
testcase_01 AC 187 ms
66,488 KB
testcase_02 AC 48 ms
62,040 KB
testcase_03 AC 107 ms
68,588 KB
testcase_04 AC 89 ms
74,424 KB
testcase_05 AC 584 ms
64,300 KB
testcase_06 AC 44 ms
61,696 KB
testcase_07 AC 44 ms
61,572 KB
testcase_08 AC 41 ms
55,588 KB
testcase_09 AC 41 ms
55,588 KB
testcase_10 AC 41 ms
55,588 KB
testcase_11 AC 41 ms
55,588 KB
testcase_12 AC 44 ms
61,696 KB
testcase_13 AC 97 ms
68,584 KB
testcase_14 AC 115 ms
70,672 KB
testcase_15 AC 122 ms
70,660 KB
testcase_16 AC 113 ms
70,660 KB
testcase_17 AC 115 ms
72,784 KB
testcase_18 AC 129 ms
72,748 KB
testcase_19 AC 65 ms
64,428 KB
testcase_20 AC 100 ms
68,592 KB
testcase_21 AC 61 ms
63,916 KB
testcase_22 AC 121 ms
72,756 KB
testcase_23 AC 41 ms
55,588 KB
testcase_24 AC 40 ms
55,588 KB
testcase_25 AC 41 ms
55,588 KB
testcase_26 AC 42 ms
55,588 KB
testcase_27 AC 41 ms
55,588 KB
testcase_28 AC 42 ms
55,588 KB
testcase_29 AC 42 ms
55,588 KB
testcase_30 AC 42 ms
55,588 KB
testcase_31 AC 44 ms
55,588 KB
testcase_32 AC 43 ms
55,588 KB
testcase_33 AC 78 ms
66,512 KB
testcase_34 AC 70 ms
70,684 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappop, heappush
from collections import defaultdict

n, k = map(int, input().split())
A = list(map(int, input().split()))
mod = 10**9 + 7

P = defaultdict(list)
C = defaultdict(int)
for i in range(n):
    a = A[i]
    f = 2
    while f * f <= a:
        cnt = 0
        while a % f == 0:
            cnt += 1
            a //= f
        if cnt > 0:
            if len(P[f]) < k:
                heappush(P[f], cnt)
                C[f] += cnt
            else:
                d = heappop(P[f])
                C[f] -= d
                res = max(d, cnt)
                heappush(P[f], res)
                C[f] += res
        f += 1
    if a != 1:
        if len(P[a]) < k:
            heappush(P[a], 1)
            C[a] += 1
        else:
            d = heappop(P[a])
            C[a] -= d
            res = max(d, 1)
            heappush(P[a], res)
            C[a] += res
ans = 1
for val, cnt in C.items():
    ans *= pow(val, cnt, mod)
    ans %= mod
print(ans)
0