結果
| 問題 |
No.2326 Factorial to the Power of Factorial to the...
|
| コンテスト | |
| ユーザー |
nikoro256
|
| 提出日時 | 2023-05-28 14:51:28 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 51 ms / 2,000 ms |
| コード長 | 452 bytes |
| コンパイル時間 | 512 ms |
| コンパイル使用メモリ | 82,176 KB |
| 実行使用メモリ | 58,240 KB |
| 最終ジャッジ日時 | 2024-12-27 03:14:48 |
| 合計ジャッジ時間 | 2,216 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 20 |
ソースコード
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)
nikoro256