結果

問題 No.2326 Factorial to the Power of Factorial to the...
ユーザー shobonvipshobonvip
提出日時 2023-05-28 13:47:03
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 629 bytes
コンパイル時間 5,550 ms
コンパイル使用メモリ 261,512 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-26 21:51:00
合計ジャッジ時間 4,865 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;

typedef modint1000000007 mint;
typedef long long ll;

ll mod_pow(ll x, ll m, int P){
	ll ret = 1;
	ll tmp = x;
	while (m > 0){
		if (m&1){
			ret = ret * tmp % P;
		}
		m >>= 1;
		tmp = tmp * tmp % P;
	}
	return ret;
}

int main(){
	int n, p; cin >> n >> p;
	int x = n;
	mint tmp = 0;
	while (x > 0){
		x = x / p;
		tmp += x;
	}
	ll kr = 1;
	ll ks = 1;
	int mod = 1'000'000'007;
	for (int i=1; i<=n; i++){
		kr *= i;
		ks *= i;
		kr %= mod - 1;
		ks %= mod;
	}
	mint ar = mod_pow(ks, kr, mod);
	tmp *= ar;
	cout << tmp.val() << endl;
}
0