結果

問題 No.368 LCM of K-products
ユーザー tktk_snsn
提出日時 2021-01-17 22:02:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,087 ms / 2,000 ms
コード長 728 bytes
コンパイル時間 266 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 319,384 KB
最終ジャッジ日時 2024-11-30 03:42:49
合計ジャッジ時間 10,814 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict


def prime_factorization(n):  # 素因数分解
    res = []
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            cnt = 0
            while n % i == 0:
                cnt += 1
                n //= i
            res.append((i, cnt))
    if n > 1:
        res.append((n, 1))
    return res


N, K = map(int, input().split())
A = list(map(int, input().split()))

dp = [defaultdict(int) for _ in range(K+1)]
for a in A:
    pf = prime_factorization(a)
    for i in reversed(range(K)):
        for p, f in pf:
            dp[i+1][p] = max(dp[i+1][p], dp[i][p] + f)

mod = 10 ** 9 + 7
ans = 1
for k, v in dp[K].items():
    ans *= pow(k, v, mod)
    ans %= mod
print(ans)
0