結果

問題 No.2326 Factorial to the Power of Factorial to the...
ユーザー hiikunZhiikunZ
提出日時 2023-05-28 13:48:08
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 803 bytes
コンパイル時間 3,065 ms
コンパイル使用メモリ 215,368 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-27 08:27:51
合計ジャッジ時間 3,977 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 3 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 4 ms
4,376 KB
testcase_07 AC 4 ms
4,376 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 4 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0