結果

問題 No.2326 Factorial to the Power of Factorial to the...
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-06-04 00:49:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 1,025 bytes
コンパイル時間 1,097 ms
コンパイル使用メモリ 105,796 KB
実行使用メモリ 4,636 KB
最終ジャッジ日時 2023-08-28 08:05:58
合計ジャッジ時間 2,204 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>

using namespace std;
using ll = long long;
const ll m7 = 1e9+7, m6 = 1e9+6;

//X!が素数pで何回割り切れるか
ll Legendre(ll X, ll p){
    ll cnt=0, q=p;
    while(X/q > 0){
        cnt += X/q;
        if (q <= X/p) q *= p;
        else break;
    }
    return cnt;
}

ll mod_exp(ll b, ll e, ll m){
    if (e > 0 && b == 0) return 0;
    ll ans = 1;
    b %= m;

    while (e > 0){
        if ((e & 1LL)) ans = (ans * b) % m;
        e = e >> 1LL;
        b = (b*b) % m;
    }

    return ans;
}

int main(){
    
    ll N, P, x;
    cin >> N >> P;
    x = Legendre(N, P);
    vector<ll> P6(N+1), P7(N+1);
    P6[0] = 1; P7[0] = 1;
    for (int i=1; i<=N; i++) P6[i] = (P6[i-1] * i) % m6;
    for (int i=1; i<=N; i++) P7[i] = (P7[i-1] * i) % m7;

    x *= mod_exp(P7[N], P6[N], m7);
    x %= m7;

    cout << x << endl;

    return 0;
}
0