結果
問題 | No.2326 Factorial to the Power of Factorial to the... |
ユーザー |
![]() |
提出日時 | 2024-12-06 13:18:04 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 559 bytes |
コンパイル時間 | 2,402 ms |
コンパイル使用メモリ | 202,224 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-06 13:18:08 |
合計ジャッジ時間 | 3,534 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 20 |
ソースコード
#include <bits/stdc++.h>using namespace std;void fast_io() {ios_base::sync_with_stdio(false);cin.tie(nullptr);}#include <atcoder/modint>using mint = atcoder::modint1000000007;const int MOD = 1e9 + 7;int main() {fast_io();int n, p;cin >> n >> p;int cnt = 0;{int pp = p;while (n >= pp) {cnt += n / pp;if (pp > INT_MAX / p) break;pp *= p;}}mint ans = 1;long long fact = 1;for (int i = 2; i <= n; i++) {ans *= i;fact *= i;fact %= (MOD - 1);}ans = ans.pow(fact) * cnt;cout << ans.val() << endl;}