結果

問題 No.2326 Factorial to the Power of Factorial to the...
ユーザー nikoro256nikoro256
提出日時 2023-05-28 14:51:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 452 bytes
コンパイル時間 1,070 ms
コンパイル使用メモリ 86,516 KB
実行使用メモリ 75,868 KB
最終ジャッジ日時 2023-08-27 10:44:39
合計ジャッジ時間 3,021 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
75,868 KB
testcase_01 AC 79 ms
75,516 KB
testcase_02 AC 77 ms
75,532 KB
testcase_03 AC 77 ms
75,536 KB
testcase_04 AC 78 ms
75,588 KB
testcase_05 AC 77 ms
75,580 KB
testcase_06 AC 78 ms
75,464 KB
testcase_07 AC 78 ms
75,520 KB
testcase_08 AC 79 ms
75,588 KB
testcase_09 AC 78 ms
75,660 KB
testcase_10 AC 78 ms
75,408 KB
testcase_11 AC 76 ms
75,656 KB
testcase_12 AC 76 ms
75,360 KB
testcase_13 AC 75 ms
75,592 KB
testcase_14 AC 77 ms
75,540 KB
testcase_15 AC 77 ms
75,660 KB
testcase_16 AC 79 ms
75,424 KB
testcase_17 AC 79 ms
75,404 KB
testcase_18 AC 79 ms
75,360 KB
testcase_19 AC 79 ms
75,464 KB
testcase_20 AC 74 ms
71,236 KB
testcase_21 AC 74 ms
71,204 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

p=10**9+7

def exp(a,b,p):
    ans,mul,div=1,a,1
    for i in range(70):
        if b//div%2==1:
            ans*=mul
            ans%=p
        mul=mul**2%p
        div*=2
    return ans%p
    
N,P=map(int,input().split())
p=10**9+7
Ps=P
Nc=N//P
while Ps*Ps<=N:
    Ps=Ps*Ps
    Nc+=N//Ps
#NbはN!をpで割ったあまり
Nb=1
for i in range(1,N+1):
    Nb*=i
    Nb%=p
Nub=1
for i in range(1,N+1):
    Nub*=i
    Nub%=(p-1)
print(Nc*exp(Nb,Nub,p)%p)
0