結果

問題 No.2365 Present of good number
ユーザー chankei271828chankei271828
提出日時 2023-06-30 23:03:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 91 ms / 2,000 ms
コード長 1,190 bytes
コンパイル時間 241 ms
コンパイル使用メモリ 87,004 KB
実行使用メモリ 71,984 KB
最終ジャッジ日時 2023-09-21 17:20:10
合計ジャッジ時間 5,558 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
71,696 KB
testcase_01 AC 89 ms
71,720 KB
testcase_02 AC 89 ms
71,432 KB
testcase_03 AC 88 ms
71,696 KB
testcase_04 AC 91 ms
71,776 KB
testcase_05 AC 88 ms
71,892 KB
testcase_06 AC 86 ms
71,984 KB
testcase_07 AC 89 ms
71,732 KB
testcase_08 AC 88 ms
71,616 KB
testcase_09 AC 87 ms
71,792 KB
testcase_10 AC 86 ms
71,980 KB
testcase_11 AC 88 ms
71,760 KB
testcase_12 AC 87 ms
71,596 KB
testcase_13 AC 87 ms
71,372 KB
testcase_14 AC 88 ms
71,772 KB
testcase_15 AC 88 ms
71,588 KB
testcase_16 AC 88 ms
71,576 KB
testcase_17 AC 87 ms
71,504 KB
testcase_18 AC 88 ms
71,496 KB
testcase_19 AC 88 ms
71,728 KB
testcase_20 AC 89 ms
71,804 KB
testcase_21 AC 89 ms
71,788 KB
testcase_22 AC 87 ms
71,844 KB
testcase_23 AC 88 ms
71,800 KB
testcase_24 AC 88 ms
71,768 KB
testcase_25 AC 88 ms
71,832 KB
testcase_26 AC 87 ms
71,896 KB
testcase_27 AC 87 ms
71,376 KB
testcase_28 AC 88 ms
71,576 KB
testcase_29 AC 87 ms
71,876 KB
testcase_30 AC 88 ms
71,472 KB
testcase_31 AC 87 ms
71,716 KB
testcase_32 AC 87 ms
71,500 KB
testcase_33 AC 87 ms
71,800 KB
testcase_34 AC 88 ms
71,500 KB
testcase_35 AC 88 ms
71,572 KB
testcase_36 AC 86 ms
71,728 KB
testcase_37 AC 87 ms
71,764 KB
testcase_38 AC 88 ms
71,724 KB
testcase_39 AC 89 ms
71,372 KB
testcase_40 AC 88 ms
71,580 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#nを素因数分解して、辞書に割れる回数も合わせて返す。
#O(sqrt(N))
import math
from collections import defaultdict
def prime_factorization(n):
    ima=n
    d={}
    for i in range(2,math.ceil(math.sqrt(n))+2):
        if i<=ima and ima%i==0:
            while ima%i==0:
                if i not in d:
                    d[i]=1
                else:
                    d[i]+=1
                ima//=i
    if ima==1:
        return d
    else:
        d[ima]=1
        return d

N,K=map(int,input().split())
mod=10**9+7
ans=1
d_now=prime_factorization(N)
for _ in range(min(K,20)):
    d_tmp=defaultdict(int)
    for p in d_now:
        d_p=prime_factorization(p+1)
        for v in d_p:
            d_tmp[v]+=d_now[p]*d_p[v]
    d_now=d_tmp
nokori=K-20
if nokori<=0:
    ans=1
    for p in d_now:
        ans*=pow(p,d_now[p],mod)
        ans%=mod
    print(ans)
elif nokori%2==0:
    a=d_now[2]*pow(2,nokori//2,mod-1)
    b=d_now[3]*pow(2,nokori//2,mod-1)
    #print(a,b)
    print(pow(2,a,mod)*pow(3,b,mod)%mod)
else:
    a=d_now[2]*pow(2,nokori//2,mod-1)
    b=d_now[3]*pow(2,nokori//2,mod-1)
    a,b=2*b,a
    #print(a,b)
    print(pow(2,a,mod)*pow(3,b,mod)%mod)
0