結果
問題 | No.368 LCM of K-products |
ユーザー |
|
提出日時 | 2024-01-03 00:28:43 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 514 ms / 2,000 ms |
コード長 | 988 bytes |
コンパイル時間 | 384 ms |
コンパイル使用メモリ | 82,164 KB |
実行使用メモリ | 76,824 KB |
最終ジャッジ日時 | 2024-09-27 18:22:13 |
合計ジャッジ時間 | 4,390 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 35 |
ソースコード
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)