結果
| 問題 |
No.2326 Factorial to the Power of Factorial to the...
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-05-28 15:39:30 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 790 bytes |
| コンパイル時間 | 1,890 ms |
| コンパイル使用メモリ | 193,680 KB |
| 最終ジャッジ日時 | 2025-02-13 13:43:08 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 11 WA * 9 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
/**
* N!中にPの因数が k 個含まれている
* ans = k * (N!^{N!})
*/
long long mod {1000000007};
long long n, p;
cin >> n >> p;
long long k {};
long long ct {p};
for (long long ct {p}; ct <= n; ct *= p) {
k += n / ct;
k %= mod;
if (n/ct < ct) break;
}
long long n_fac {1};
for (long long i=1;i<=n;++i) {
n_fac *= i;
n_fac %= mod;
}
//cout << "fac[i]:" << n_fac << '\n';
long long n_fac_pow {n_fac};
long long ans {1};
for (long long c = n_fac; c != 0; c>>=1) {
if (c & 1) ans *= n_fac_pow;
n_fac_pow *= n_fac_pow;
ans %= mod;
n_fac_pow %= mod;
}
ans *= k;
ans %= mod;
cout << ans << '\n';
}