結果
| 問題 |
No.2326 Factorial to the Power of Factorial to the...
|
| コンテスト | |
| ユーザー |
srjywrdnprkt
|
| 提出日時 | 2023-06-04 00:49:00 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 5 ms / 2,000 ms |
| コード長 | 1,025 bytes |
| コンパイル時間 | 1,173 ms |
| コンパイル使用メモリ | 103,976 KB |
| 最終ジャッジ日時 | 2025-02-13 22:29:51 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 20 |
ソースコード
#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
using namespace std;
using ll = long long;
const ll m7 = 1e9+7, m6 = 1e9+6;
//X!が素数pで何回割り切れるか
ll Legendre(ll X, ll p){
ll cnt=0, q=p;
while(X/q > 0){
cnt += X/q;
if (q <= X/p) q *= p;
else break;
}
return cnt;
}
ll mod_exp(ll b, ll e, ll m){
if (e > 0 && b == 0) return 0;
ll ans = 1;
b %= m;
while (e > 0){
if ((e & 1LL)) ans = (ans * b) % m;
e = e >> 1LL;
b = (b*b) % m;
}
return ans;
}
int main(){
ll N, P, x;
cin >> N >> P;
x = Legendre(N, P);
vector<ll> P6(N+1), P7(N+1);
P6[0] = 1; P7[0] = 1;
for (int i=1; i<=N; i++) P6[i] = (P6[i-1] * i) % m6;
for (int i=1; i<=N; i++) P7[i] = (P7[i-1] * i) % m7;
x *= mod_exp(P7[N], P6[N], m7);
x %= m7;
cout << x << endl;
return 0;
}
srjywrdnprkt