結果
| 問題 |
No.2326 Factorial to the Power of Factorial to the...
|
| コンテスト | |
| ユーザー |
shobonvip
|
| 提出日時 | 2023-05-28 13:47:03 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 19 ms / 2,000 ms |
| コード長 | 629 bytes |
| コンパイル時間 | 3,775 ms |
| コンパイル使用メモリ | 250,108 KB |
| 最終ジャッジ日時 | 2025-02-13 10:17:41 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 20 |
ソースコード
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
typedef modint1000000007 mint;
typedef long long ll;
ll mod_pow(ll x, ll m, int P){
ll ret = 1;
ll tmp = x;
while (m > 0){
if (m&1){
ret = ret * tmp % P;
}
m >>= 1;
tmp = tmp * tmp % P;
}
return ret;
}
int main(){
int n, p; cin >> n >> p;
int x = n;
mint tmp = 0;
while (x > 0){
x = x / p;
tmp += x;
}
ll kr = 1;
ll ks = 1;
int mod = 1'000'000'007;
for (int i=1; i<=n; i++){
kr *= i;
ks *= i;
kr %= mod - 1;
ks %= mod;
}
mint ar = mod_pow(ks, kr, mod);
tmp *= ar;
cout << tmp.val() << endl;
}
shobonvip