結果
問題 |
No.2326 Factorial to the Power of Factorial to the...
|
ユーザー |
|
提出日時 | 2023-05-28 15:57:04 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 797 bytes |
コンパイル時間 | 1,658 ms |
コンパイル使用メモリ | 193,496 KB |
最終ジャッジ日時 | 2025-02-13 14:41:52 |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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 {}; for (long long ct {p}; ct <= n; ct *= p) { k += n / ct; k %= mod; } if (k == 0) { cout << "0\n"; return 0; } 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'; }