結果

問題 No.2326 Factorial to the Power of Factorial to the...
ユーザー stunniita
提出日時 2023-05-28 16:53:30
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 408 ms / 2,000 ms
コード長 406 bytes
コンパイル時間 576 ms
コンパイル使用メモリ 12,288 KB
実行使用メモリ 11,648 KB
最終ジャッジ日時 2024-12-27 12:13:30
合計ジャッジ時間 5,781 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

MOD = 10 ** 9 + 7
N,P = map(int, input().split())

# るしゃんどる
fst = 0
fst_p = P
while True:
    x = N // fst_p
    if x == 0:break
    fst += x
    fst_p *= P

#print(f"{fst=}")

# N! mod P
snd = 1
for i in range(1,N+1):
    snd *= i
    snd %= MOD

if snd == 0: snd = MOD

#print(f"{snd=}")

thd = math.factorial(N)

#print(f"{thd=}")

ans = fst * pow(snd,thd,MOD)

print(ans % MOD)
0