結果

問題 No.2365 Present of good number
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2023-06-30 21:56:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 1,526 bytes
コンパイル時間 577 ms
コンパイル使用メモリ 87,024 KB
実行使用メモリ 75,624 KB
最終ジャッジ日時 2023-09-21 15:51:09
合計ジャッジ時間 5,111 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,128 KB
testcase_01 AC 74 ms
71,292 KB
testcase_02 AC 79 ms
75,308 KB
testcase_03 AC 78 ms
75,468 KB
testcase_04 AC 79 ms
75,440 KB
testcase_05 AC 80 ms
75,324 KB
testcase_06 AC 78 ms
75,472 KB
testcase_07 AC 79 ms
75,208 KB
testcase_08 AC 78 ms
75,360 KB
testcase_09 AC 80 ms
75,360 KB
testcase_10 AC 82 ms
75,244 KB
testcase_11 AC 80 ms
75,352 KB
testcase_12 AC 79 ms
75,404 KB
testcase_13 AC 80 ms
75,624 KB
testcase_14 AC 80 ms
75,148 KB
testcase_15 AC 78 ms
75,152 KB
testcase_16 AC 75 ms
71,068 KB
testcase_17 AC 75 ms
71,424 KB
testcase_18 AC 75 ms
71,080 KB
testcase_19 AC 72 ms
71,340 KB
testcase_20 AC 73 ms
71,356 KB
testcase_21 AC 76 ms
75,360 KB
testcase_22 AC 78 ms
75,348 KB
testcase_23 AC 81 ms
75,568 KB
testcase_24 AC 78 ms
75,388 KB
testcase_25 AC 80 ms
75,100 KB
testcase_26 AC 79 ms
75,408 KB
testcase_27 AC 79 ms
75,232 KB
testcase_28 AC 78 ms
75,308 KB
testcase_29 AC 79 ms
75,372 KB
testcase_30 AC 76 ms
75,328 KB
testcase_31 AC 75 ms
71,340 KB
testcase_32 AC 74 ms
71,076 KB
testcase_33 AC 73 ms
71,084 KB
testcase_34 AC 73 ms
71,232 KB
testcase_35 AC 75 ms
71,268 KB
testcase_36 AC 78 ms
75,352 KB
testcase_37 AC 78 ms
75,392 KB
testcase_38 AC 79 ms
75,348 KB
testcase_39 AC 77 ms
75,304 KB
testcase_40 AC 77 ms
75,304 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

"""

2冪になると、あとは
2^k -> 3^k -> 2^(2k)
みたいになる

他にループするのあるのかな…
無いと決め打って書いてみようかな

f(p1*p2) = f(p1) * f(p2)

"""

import sys
from sys import stdin

mod = 10**9+7

dic = {}
def f(N,k):

    p = []
    a = []

    if k == 0:
        return N
    if (N,k) in dic:
        return dic[(N,k)]

    Nori = N

    for i in range(2,N+1):
        if N % i == 0:
            p.append(i)
            a.append(0)
            while N % i == 0:
                a[-1] += 1
                N //= i

    ans = 1

    #print (p,a)
    
    for np,na in zip(p,a):

        # 2冪の処理
        if np == 2:
            if k % 2 == 0:
                x = (k//2)
                now = pow(2 , ( na * pow(2,x,mod-1) ) % (mod-1) , mod )
            else:
                x = (k//2)
                now = pow(3 , ( na * pow(2,x,mod-1) ) % (mod-1) , mod )
            ans = ans * now % mod

        # 3冪の処理
        if np == 3:
            if k % 2 == 0:
                x = (k//2)
                now = pow(3 , ( na * pow(2,x,mod-1) ) % (mod-1) , mod )
            else:
                x = (k//2) + 1
                now = pow(2 , ( na * pow(2,x,mod-1) ) % (mod-1) , mod )
            ans = ans * now % mod

        # そうでない場合、愚直に処理
        if np > 3:
            now = f( (np+1) ** na , k-1 )
            ans = ans * now % mod

    dic[(Nori,k)] = ans
    return ans
    

N,K = map(int,stdin.readline().split())

print (f(N,K))
0