結果

問題 No.2365 Present of good number
ユーザー tassei903tassei903
提出日時 2023-06-30 22:07:02
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 127 ms / 2,000 ms
コード長 1,121 bytes
コンパイル時間 260 ms
コンパイル使用メモリ 87,028 KB
実行使用メモリ 80,032 KB
最終ジャッジ日時 2023-09-21 16:08:11
合計ジャッジ時間 7,368 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
79,716 KB
testcase_01 AC 119 ms
79,756 KB
testcase_02 AC 119 ms
79,664 KB
testcase_03 AC 122 ms
79,764 KB
testcase_04 AC 122 ms
79,780 KB
testcase_05 AC 122 ms
79,776 KB
testcase_06 AC 121 ms
79,956 KB
testcase_07 AC 121 ms
79,748 KB
testcase_08 AC 122 ms
79,884 KB
testcase_09 AC 122 ms
79,816 KB
testcase_10 AC 121 ms
79,776 KB
testcase_11 AC 123 ms
80,032 KB
testcase_12 AC 123 ms
79,668 KB
testcase_13 AC 123 ms
79,816 KB
testcase_14 AC 123 ms
79,952 KB
testcase_15 AC 123 ms
79,672 KB
testcase_16 AC 121 ms
79,944 KB
testcase_17 AC 124 ms
79,656 KB
testcase_18 AC 125 ms
79,708 KB
testcase_19 AC 122 ms
79,708 KB
testcase_20 AC 122 ms
79,604 KB
testcase_21 AC 122 ms
79,636 KB
testcase_22 AC 121 ms
79,884 KB
testcase_23 AC 121 ms
79,668 KB
testcase_24 AC 121 ms
79,716 KB
testcase_25 AC 123 ms
79,880 KB
testcase_26 AC 120 ms
79,572 KB
testcase_27 AC 122 ms
79,712 KB
testcase_28 AC 123 ms
79,748 KB
testcase_29 AC 123 ms
79,720 KB
testcase_30 AC 121 ms
79,952 KB
testcase_31 AC 124 ms
79,948 KB
testcase_32 AC 122 ms
79,704 KB
testcase_33 AC 123 ms
79,748 KB
testcase_34 AC 122 ms
79,976 KB
testcase_35 AC 127 ms
79,712 KB
testcase_36 AC 121 ms
79,888 KB
testcase_37 AC 121 ms
79,600 KB
testcase_38 AC 122 ms
79,716 KB
testcase_39 AC 120 ms
79,668 KB
testcase_40 AC 120 ms
79,868 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

m = 10**5+100
a = [-1] * m
p = []
d = dict()
for i in range(2, m):
    if a[i] == -1:
        d[i] = len(p)
        p.append(i)
        for j in range(i, m, i):
            a[j] = i
pl = len(p)

from collections import defaultdict
def f(x):
    res = defaultdict(int)
    while x != 1:
        q = a[x]
        c = 0
        while x % q == 0:
            x //= q
            c += 1
        res[q] = c
    return res

def g(a, b, k):
    if k % 2 == 0:
        return pow(2, pow(2, k//2, mod-1)*a, mod)*pow(3, pow(2, k//2, mod-1)*b, mod)%mod
    else:
        return pow(2, pow(2, (k+1)//2, mod-1)*b, mod)*pow(3, pow(2, k//2, mod-1)*a, mod)%mod

b = []
for q in p:
    if q < 10**5+10:
        b.append(f(q+1))

c = f(n)
for i in range(k):
    if len(c) <= 2 and sum([x == 2 or x == 3 for x in c]) == len(c):
        print(g(c[2], c[3], k-i))
        exit()
    nxt = defaultdict(int)
    for q in c:
        for r in b[d[q]]:
            nxt[r] += b[d[q]][r] * c[q] 
    c = nxt
    #print(c)
    
ans = 1

for i in c:
    ans *= pow(i, c[i], mod)
    ans %= mod
print(ans)
0