結果

問題 No.2380 Sylow P-subgroup
ユーザー InTheBloomInTheBloom
提出日時 2023-07-14 21:32:58
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 938 bytes
コンパイル時間 2,950 ms
コンパイル使用メモリ 159,164 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-14 11:34:02
合計ジャッジ時間 2,701 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import std;

void read(T...)(string S, ref T args) {
    auto buf = S.split;
    foreach (i, ref arg; args) {
        arg = buf[i].to!(typeof(arg));
    }
}

void main () {
    long N;
    int P;
    readln.read(N, P);
    solve(N, P);
}

void solve (long N, int P) {
    // よくわからんけど、N!のうち素因数Pがどれだけ入ってるかっていうことちゃうか?
    const long MOD = 998244353;
    long count = 0;
    long prime = P;
    while (N/prime != 0) {
        count += N / prime;
        prime *= P;
    }

    writeln(modpow(P, count, MOD));
}

long modpow (long a, long x, const long MOD) {
    assert(0 <= a);
    assert(0 <= x);
    if (x == 0) {
        return 1L % MOD;
    }
    if (x == 1) {
        return a % MOD;
    }

    if (x % 2 == 0) {
        auto res = modpow(a, x/2, MOD);
        return res*res % MOD;
    } else {
        return a*modpow(a, x-1, MOD) % MOD;
    }

    assert(0);
}
0