結果

問題 No.368 LCM of K-products
コンテスト
ユーザー roaris
提出日時 2019-12-12 19:09:34
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 130 ms / 2,000 ms
コード長 739 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 289 ms
コンパイル使用メモリ 85,696 KB
実行使用メモリ 75,020 KB
最終ジャッジ日時 2026-03-11 21:20:42
合計ジャッジ時間 3,475 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from collections import defaultdict

def factorize(n):
    factors = []
    
    for i in range(2, int(n**0.5)+1):
        cnt = 0
        
        while n%i==0:
            n //= i
            cnt += 1
    
        if cnt>0:
            factors.append((i, cnt))
    
    if n>1:
        factors.append((n, 1))
    
    return factors

N, K = map(int, input().split())
a = list(map(int, input().split()))
MOD = 10**9+7
d = defaultdict(list)

for ai in a:
    factors = factorize(ai)
    
    for v, c in factors:
        d[v].append(c)

ans = 1

for v in d.keys():
    d[v].sort(reverse=True)
    
    if len(d[v])<K:
        ans *= pow(v, sum(d[v]), MOD)
    else:
        ans *= pow(v, sum(d[v][:K]), MOD)
    
    ans %= MOD

print(ans)
0