結果

問題 No.2326 Factorial to the Power of Factorial to the...
ユーザー 094
提出日時 2023-05-28 15:14:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 238 ms / 2,000 ms
コード長 473 bytes
コンパイル時間 182 ms
コンパイル使用メモリ 82,236 KB
実行使用メモリ 79,104 KB
最終ジャッジ日時 2024-12-27 05:28:52
合計ジャッジ時間 3,768 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

n, p = map(int, input().split())
nfact_cnt = 0
tmp = n


while tmp > 0:
	nfact_cnt += tmp // p
	tmp = tmp // p

MOD = 10**9 + 7
N = 10**5 + 1010

fact = [1]*(N+1)
r = 1
for i in range(1, N+1):
    fact[i] = r = r * i % MOD

nfact = fact[n]

#print(nfact_cnt, pow(nfact, nfact, MOD))
#print(nfact_cnt * pow(nfact, nfact, MOD) % MOD)

fc = math.factorial(n)
#print("===")

#print(nfact_cnt, pow(nfact, fc, MOD) % MOD)
print(nfact_cnt * pow(nfact, fc, MOD) % MOD)
0