結果

問題 No.2365 Present of good number
ユーザー lloyzlloyz
提出日時 2023-06-30 22:24:42
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,638 bytes
コンパイル時間 308 ms
コンパイル使用メモリ 86,936 KB
実行使用メモリ 78,628 KB
最終ジャッジ日時 2023-09-21 16:31:57
合計ジャッジ時間 6,507 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 109 ms
78,284 KB
testcase_01 AC 110 ms
78,372 KB
testcase_02 WA -
testcase_03 AC 112 ms
78,480 KB
testcase_04 AC 109 ms
78,628 KB
testcase_05 AC 110 ms
78,208 KB
testcase_06 AC 110 ms
78,488 KB
testcase_07 AC 110 ms
78,544 KB
testcase_08 AC 110 ms
78,284 KB
testcase_09 AC 109 ms
78,456 KB
testcase_10 AC 112 ms
78,576 KB
testcase_11 AC 110 ms
78,312 KB
testcase_12 AC 110 ms
78,560 KB
testcase_13 AC 110 ms
78,268 KB
testcase_14 WA -
testcase_15 AC 108 ms
78,468 KB
testcase_16 AC 110 ms
78,580 KB
testcase_17 AC 111 ms
78,276 KB
testcase_18 AC 109 ms
78,288 KB
testcase_19 AC 110 ms
78,372 KB
testcase_20 AC 113 ms
78,544 KB
testcase_21 AC 111 ms
78,488 KB
testcase_22 AC 111 ms
78,208 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 110 ms
78,280 KB
testcase_26 AC 110 ms
78,268 KB
testcase_27 AC 110 ms
78,576 KB
testcase_28 AC 109 ms
78,312 KB
testcase_29 AC 111 ms
78,432 KB
testcase_30 AC 110 ms
78,432 KB
testcase_31 AC 110 ms
78,472 KB
testcase_32 AC 109 ms
78,416 KB
testcase_33 AC 109 ms
78,268 KB
testcase_34 WA -
testcase_35 AC 111 ms
78,056 KB
testcase_36 AC 110 ms
78,328 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 110 ms
78,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

IsPrime = [True for _ in range(10**5 + 1)]
IsPrime[0] = IsPrime[1] = False
Primes = []
for i in range(2, 10**5 + 1):
    if IsPrime[i]:
        Primes.append(i)
        for j in range(i * i, 10**5 + 1, i):
            IsPrime[j] = False

n, k = map(int, input().split())
mod = 10**9 + 7

P = defaultdict(int)
seen = set()
for prime in Primes:
    while n % prime == 0:
        seen.add(prime)
        P[prime] += 1
        n //= prime
C = [(p, c) for p, c in P.items()]
while not (len(seen) <= 2 and (2 in seen or 3 in seen)) and k > 0:
    k -= 1
    P = defaultdict(int)
    seen = set()
    for p, c in C:
        p += 1
        if IsPrime[p]:
            seen.add(p)
            P[p] += c
        else:
            for prime in Primes:
                while p % prime == 0:
                    seen.add(prime)
                    P[prime] += c
                    p //= prime
                if p == 1:
                    break
    C = [(p, c) for p, c in P.items()]

if k > 0:
    q, r = divmod(k, 2)
    P = defaultdict(int)
    for p, c in C:
        if p == 2:
            if r == 0:
                P[2] += c * pow(2, q, mod - 1)
                P[2] %= mod - 1
            else:
                P[3] += c * pow(2, q, mod - 1)
                P[3] %= mod - 1
        else:
            if r == 0:
                P[3] += c * pow(2, q, mod - 1)
                P[3] %= mod - 1
            else:
                P[2] += c * pow(2, q + 1, mod - 1)
                P[2] %= mod - 1
    C = [(p, c) for p, c in P.items()]

ans = 1
for p, c in C:
    ans *= pow(p, c, mod)
    ans %= mod
print(ans)
0