結果

問題 No.368 LCM of K-products
ユーザー 👑 rin204rin204
提出日時 2022-10-30 16:32:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 202 ms / 2,000 ms
コード長 1,812 bytes
コンパイル時間 959 ms
コンパイル使用メモリ 87,060 KB
実行使用メモリ 80,968 KB
最終ジャッジ日時 2023-09-21 14:06:22
合計ジャッジ時間 6,853 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 169 ms
78,120 KB
testcase_01 AC 153 ms
78,492 KB
testcase_02 AC 104 ms
77,064 KB
testcase_03 AC 202 ms
80,968 KB
testcase_04 AC 182 ms
78,424 KB
testcase_05 AC 104 ms
76,652 KB
testcase_06 AC 72 ms
71,180 KB
testcase_07 AC 73 ms
71,128 KB
testcase_08 AC 73 ms
71,236 KB
testcase_09 AC 72 ms
71,160 KB
testcase_10 AC 75 ms
71,448 KB
testcase_11 AC 73 ms
71,352 KB
testcase_12 AC 73 ms
71,564 KB
testcase_13 AC 135 ms
77,620 KB
testcase_14 AC 142 ms
77,964 KB
testcase_15 AC 162 ms
78,856 KB
testcase_16 AC 157 ms
78,436 KB
testcase_17 AC 139 ms
77,872 KB
testcase_18 AC 157 ms
79,296 KB
testcase_19 AC 107 ms
76,544 KB
testcase_20 AC 156 ms
79,188 KB
testcase_21 AC 92 ms
76,532 KB
testcase_22 AC 163 ms
78,516 KB
testcase_23 AC 76 ms
71,352 KB
testcase_24 AC 75 ms
71,376 KB
testcase_25 AC 74 ms
71,260 KB
testcase_26 AC 76 ms
71,612 KB
testcase_27 AC 76 ms
71,376 KB
testcase_28 AC 74 ms
71,148 KB
testcase_29 AC 74 ms
71,588 KB
testcase_30 AC 75 ms
71,260 KB
testcase_31 AC 80 ms
71,572 KB
testcase_32 AC 76 ms
71,380 KB
testcase_33 AC 125 ms
77,936 KB
testcase_34 AC 143 ms
78,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd

MOD = 10 ** 9 + 7

def isprime(n):
    if n <= 1:
        return False
    elif n == 2:
        return True
    elif n % 2 == 0:
        return False
    
    A = [2, 325, 9375, 28178, 450775, 9780504, 1795265022]
    s = 0
    d = n - 1
    while d % 2 == 0:
        s += 1
        d >>= 1
    
    for a in A:
        if a % n == 0:
            return True
        x = pow(a, d, n)
        if x != 1:
            for t in range(s):
                if x == n - 1:
                    break
                x = x * x % n
            else:
                return False
    return True
        
def pollard(n):
    if n % 2 == 0:
        return 2
    if isprime(n):
        return n
    
    f = lambda x:(x * x + 1) % n
    
    step = 0
    while 1:
        step += 1
        x = step
        y = f(x)
        while 1:
            p = gcd(y - x + n, n)
            if p == 0 or p == n:
                break
            if p != 1:
                return p
            x = f(x)
            y = f(f(y))

def primefact(n):
    if n == 1:
        return []
    p = pollard(n)
    if p == n:
        return [p]
    left = primefact(p)
    right = primefact(n // p)
    left += right
    return sorted(left)


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

cnt = {}
for a in A:
    if a == 1:
        continue
    primes = primefact(a)
    bef = primes[0]
    c = 0
    for p in primes:
        if p != bef:
            if bef not in cnt:
                cnt[bef] = []
            cnt[bef].append(c)
            c = 1
            bef = p
        else:
            c += 1
    if bef not in cnt:
        cnt[bef] = []
    cnt[bef].append(c)

ans = 1
for k, v in cnt.items():
    v.sort(reverse=True)
    tot = sum(v[:K])
    ans *= pow(k, tot, MOD)
    ans %= MOD
print(ans)
0