結果

問題 No.2365 Present of good number
ユーザー lloyzlloyz
提出日時 2023-06-30 22:41:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 113 ms / 2,000 ms
コード長 1,812 bytes
コンパイル時間 1,169 ms
コンパイル使用メモリ 86,964 KB
実行使用メモリ 78,508 KB
最終ジャッジ日時 2023-09-21 16:51:59
合計ジャッジ時間 7,179 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 105 ms
78,124 KB
testcase_01 AC 108 ms
78,484 KB
testcase_02 AC 106 ms
78,404 KB
testcase_03 AC 106 ms
78,364 KB
testcase_04 AC 107 ms
78,244 KB
testcase_05 AC 106 ms
78,320 KB
testcase_06 AC 104 ms
78,496 KB
testcase_07 AC 105 ms
78,132 KB
testcase_08 AC 107 ms
78,200 KB
testcase_09 AC 106 ms
78,220 KB
testcase_10 AC 105 ms
78,136 KB
testcase_11 AC 104 ms
78,464 KB
testcase_12 AC 107 ms
78,220 KB
testcase_13 AC 108 ms
78,220 KB
testcase_14 AC 107 ms
78,508 KB
testcase_15 AC 107 ms
78,108 KB
testcase_16 AC 105 ms
78,100 KB
testcase_17 AC 104 ms
78,200 KB
testcase_18 AC 106 ms
78,284 KB
testcase_19 AC 104 ms
78,400 KB
testcase_20 AC 104 ms
78,352 KB
testcase_21 AC 105 ms
78,220 KB
testcase_22 AC 103 ms
78,400 KB
testcase_23 AC 106 ms
78,340 KB
testcase_24 AC 104 ms
78,172 KB
testcase_25 AC 103 ms
78,356 KB
testcase_26 AC 103 ms
78,108 KB
testcase_27 AC 104 ms
78,284 KB
testcase_28 AC 106 ms
78,068 KB
testcase_29 AC 107 ms
78,056 KB
testcase_30 AC 108 ms
78,220 KB
testcase_31 AC 105 ms
78,200 KB
testcase_32 AC 105 ms
78,452 KB
testcase_33 AC 102 ms
78,128 KB
testcase_34 AC 104 ms
78,376 KB
testcase_35 AC 105 ms
78,184 KB
testcase_36 AC 106 ms
78,344 KB
testcase_37 AC 106 ms
78,372 KB
testcase_38 AC 113 ms
78,368 KB
testcase_39 AC 105 ms
78,152 KB
testcase_40 AC 105 ms
78,296 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
    if n == 1:
        break
C = [(p, c) for p, c in P.items()]
while k > 0:
    if len(seen) == 2 and 2 in seen and 3 in seen:
        break
    if len(seen) == 1 and (2 in seen or 3 in seen):
        break
    k -= 1
    P = defaultdict(int)
    seen = set()
    for p, c in C:
        p += 1
        if IsPrime[p]:
            seen.add(p)
            P[p] += c
            P[p] %= mod - 1
        else:
            for prime in Primes:
                while p % prime == 0:
                    seen.add(prime)
                    P[prime] += c
                    P[prime] %= mod - 1
                    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