結果

問題 No.368 LCM of K-products
ユーザー 👑 rin204rin204
提出日時 2022-10-30 16:31:13
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,780 bytes
コンパイル時間 664 ms
コンパイル使用メモリ 86,824 KB
実行使用メモリ 80,676 KB
最終ジャッジ日時 2023-09-21 14:05:09
合計ジャッジ時間 5,751 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 155 ms
78,172 KB
testcase_01 AC 149 ms
78,308 KB
testcase_02 AC 99 ms
77,008 KB
testcase_03 AC 189 ms
80,676 KB
testcase_04 AC 173 ms
78,160 KB
testcase_05 AC 97 ms
76,536 KB
testcase_06 AC 70 ms
71,204 KB
testcase_07 AC 69 ms
71,260 KB
testcase_08 AC 70 ms
71,484 KB
testcase_09 AC 69 ms
71,164 KB
testcase_10 AC 71 ms
71,172 KB
testcase_11 AC 71 ms
71,512 KB
testcase_12 AC 71 ms
71,288 KB
testcase_13 AC 124 ms
77,744 KB
testcase_14 AC 136 ms
77,676 KB
testcase_15 AC 157 ms
78,836 KB
testcase_16 AC 153 ms
78,248 KB
testcase_17 AC 134 ms
77,944 KB
testcase_18 AC 150 ms
79,328 KB
testcase_19 AC 98 ms
76,448 KB
testcase_20 AC 147 ms
78,800 KB
testcase_21 AC 88 ms
76,660 KB
testcase_22 AC 153 ms
78,672 KB
testcase_23 AC 70 ms
71,104 KB
testcase_24 AC 69 ms
71,456 KB
testcase_25 AC 70 ms
71,360 KB
testcase_26 AC 69 ms
71,100 KB
testcase_27 AC 70 ms
71,080 KB
testcase_28 AC 70 ms
71,364 KB
testcase_29 AC 70 ms
71,508 KB
testcase_30 AC 70 ms
71,324 KB
testcase_31 RE -
testcase_32 AC 71 ms
71,328 KB
testcase_33 AC 120 ms
77,700 KB
testcase_34 RE -
権限があれば一括ダウンロードができます

ソースコード

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:
    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