結果

問題 No.2365 Present of good number
ユーザー lloyzlloyz
提出日時 2023-06-30 22:23:25
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,642 bytes
コンパイル時間 234 ms
コンパイル使用メモリ 87,076 KB
実行使用メモリ 78,788 KB
最終ジャッジ日時 2023-09-21 16:30:37
合計ジャッジ時間 5,864 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 109 ms
78,212 KB
testcase_01 AC 102 ms
78,264 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 103 ms
78,292 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 101 ms
78,272 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 103 ms
78,420 KB
testcase_11 AC 101 ms
78,304 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 100 ms
78,276 KB
testcase_20 AC 99 ms
78,444 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 100 ms
78,352 KB
testcase_26 WA -
testcase_27 AC 101 ms
78,212 KB
testcase_28 AC 100 ms
78,472 KB
testcase_29 AC 102 ms
78,332 KB
testcase_30 AC 103 ms
78,664 KB
testcase_31 WA -
testcase_32 AC 102 ms
78,356 KB
testcase_33 AC 101 ms
78,424 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 103 ms
78,524 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 104 ms
78,580 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 + 1, 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