結果
| 問題 | No.2326 Factorial to the Power of Factorial to the... |
| コンテスト | |
| ユーザー |
srjywrdnprkt
|
| 提出日時 | 2023-06-04 00:49:00 |
| 言語 | C++17 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 3 ms / 2,000 ms |
| + 465µs | |
| コード長 | 1,025 bytes |
| 記録 | |
| コンパイル時間 | 725 ms |
| コンパイル使用メモリ | 130,516 KB |
| 実行使用メモリ | 9,796 KB |
| 最終ジャッジ日時 | 2026-10-16 16:40:07 |
| 合計ジャッジ時間 | 2,326 ms |
|
ジャッジサーバーID (参考情報) |
judge4_0 / judge5_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 21 |
ソースコード
#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