結果
| 問題 |
No.2326 Factorial to the Power of Factorial to the...
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-05-28 13:48:08 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 31 ms / 2,000 ms |
| コード長 | 803 bytes |
| コンパイル時間 | 2,894 ms |
| コンパイル使用メモリ | 216,516 KB |
| 最終ジャッジ日時 | 2025-02-13 10:19:54 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 20 |
ソースコード
#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
ll MOD = 1000000007;
ll modpow(ll A,ll B,ll M){
ll r = 1,p = A;
while(B > 0){
if(B % 2 == 1) r = (r * p) % M;
p = (p * p) % M;
B /= 2;
}
return r;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll N,P;
cin >> N >> P;
ll f = 1,g = 1;
for(ll i = 1;i <= N;i++){
f *= i;
f %= MOD;
g *= i;
g %= (MOD - 1);
}
ll h = 0;
for(ll i = P;i <= N;i *= P){
h += N / i;
}
ll ans = modpow(f,g,MOD);
ans *= h;
ans %= MOD;
cout << ans << endl;
}