結果

問題 No.2380 Sylow P-subgroup
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-07-20 17:03:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 662 bytes
コンパイル時間 1,995 ms
コンパイル使用メモリ 201,348 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-20 17:31:11
合計ジャッジ時間 3,647 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

const ll m1 = 998244352;
const ll m2 = 998244353;

ll Legendre(ll X, ll p){
    ll cnt=0, q=p;
    while(X/q > 0){
        cnt += (X/q) % m1;
        cnt %= m1;
        if (q <= X/p) q *= p;
        else break;
    }
    return cnt;
}

int main(){

    ll N, P, e;
    cin >> N >> P;
    e = Legendre(N, P);
    cout << mod_exp(P, e, m2) << endl;

    return 0;
}
0