結果

問題 No.368 LCM of K-products
ユーザー 🍡yurahuna🍡yurahuna
提出日時 2016-04-11 22:17:14
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 534 ms / 2,000 ms
コード長 1,087 bytes
コンパイル時間 542 ms
コンパイル使用メモリ 11,912 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2023-10-23 21:08:30
合計ジャッジ時間 10,573 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 400 ms
10,452 KB
testcase_01 AC 500 ms
10,752 KB
testcase_02 AC 490 ms
10,368 KB
testcase_03 AC 499 ms
10,404 KB
testcase_04 AC 503 ms
10,452 KB
testcase_05 AC 534 ms
10,448 KB
testcase_06 AC 60 ms
10,556 KB
testcase_07 AC 61 ms
10,556 KB
testcase_08 AC 61 ms
10,556 KB
testcase_09 AC 62 ms
10,556 KB
testcase_10 AC 62 ms
10,556 KB
testcase_11 AC 60 ms
10,556 KB
testcase_12 AC 64 ms
10,556 KB
testcase_13 AC 301 ms
10,384 KB
testcase_14 AC 432 ms
10,752 KB
testcase_15 AC 478 ms
10,752 KB
testcase_16 AC 435 ms
10,752 KB
testcase_17 AC 366 ms
10,444 KB
testcase_18 AC 486 ms
10,752 KB
testcase_19 AC 171 ms
10,324 KB
testcase_20 AC 339 ms
10,432 KB
testcase_21 AC 129 ms
10,324 KB
testcase_22 AC 466 ms
10,752 KB
testcase_23 AC 60 ms
10,556 KB
testcase_24 AC 60 ms
10,556 KB
testcase_25 AC 62 ms
10,556 KB
testcase_26 AC 60 ms
10,556 KB
testcase_27 AC 63 ms
10,556 KB
testcase_28 AC 60 ms
10,556 KB
testcase_29 AC 63 ms
10,556 KB
testcase_30 AC 64 ms
10,556 KB
testcase_31 AC 64 ms
10,556 KB
testcase_32 AC 62 ms
10,556 KB
testcase_33 AC 228 ms
10,340 KB
testcase_34 AC 483 ms
10,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict as ddict

# sqrt(10^9) < 40000未満の素数をあらかじめ列挙しておく (4203個)
prime = []
memo = [True] * 40000
i = 2
while i < 40000:
    if memo[i]:
        prime.append(i)
        j = 2 * i
        while j < 40000:
            memo[j] = False
            j += i
    i += 1

# print(len(prime))

###########################

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

exponents = ddict(list)
for ax in a:
    # 素因数分解(作成済みの素数表primeを使う)
    cnt = ddict(int)
    for p in prime:
        while ax % p == 0:
            ax //= p
            cnt[p] += 1

    # sqrt(10^9) 以下の素数で割り切れなかったら、a_iは素数
    if ax != 1:
        cnt[ax] += 1

    for key, value in cnt.items():
        exponents[key].append(value)

# print(exponents)

mod = 10**9 + 7

ans = 1
for prime, li in exponents.items():
    li.sort(reverse = True)
    num = 0
    for i in range(min(K, len(li))):
        num += li[i]

    ans *= pow(prime, num, mod)
    ans %= mod

print(ans)
0