結果

問題 No.2576 LCM Pattern
ユーザー Yilin FeiYilin Fei
提出日時 2024-01-08 17:08:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,151 bytes
コンパイル時間 1,034 ms
コンパイル使用メモリ 84,972 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-01-08 17:08:22
合計ジャッジ時間 2,280 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <cmath>

const int mod = 998244353;

// 素因数分解函数
std::map<int, int> prime_factorize(int n) {
    std::map<int, int> prime_factors;
    while (n % 2 == 0) {
        prime_factors[2]++;
        n /= 2;
    }
    int f = 3;
    while (f * f <= n) {
        if (n % f == 0) {
            prime_factors[f]++;
            n /= f;
        } else {
            f += 2;
        }
    }
    if (n != 1) {
        prime_factors[n]++;
    }
    return prime_factors;
}

// 快速幂函数,用于计算 a^b % mod
long long modpow(long long base, int exp, int modulus) {
    base %= modulus;
    long long result = 1;
    while (exp > 0) {
        if (exp & 1) result = (result * base) % modulus;
        base = (base * base) % modulus;
        exp >>= 1;
    }
    return result;
}

int main() {
    int N, M;
    std::cin >> N >> M;

    auto CP = prime_factorize(M);
    long long ans = 1;
    for (auto const& kvp : CP) {
        int v = kvp.second;
        ans = ans * (modpow(v + 1, N, mod) - modpow(v, N, mod) + mod) % mod;
    }

    std::cout << ans << std::endl;
    return 0;
}
0