結果

問題 No.3799 1 + 6 = 7 (Another version)
ユーザー 👑 potato167
提出日時 2026-11-13 02:58:39
言語 C++17
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 750 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,289 ms
コンパイル使用メモリ 215,944 KB
実行使用メモリ 9,932 KB
最終ジャッジ日時 2026-11-13 22:07:49
合計ジャッジ時間 3,854 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge5_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other AC * 32 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>

using i64 = long long;
constexpr i64 P = 998244353;

i64 norm(i64 a) {
    a %= P;
    if (a < 0) a += P;
    return a;
}

i64 modpow(i64 a, i64 e) {
    i64 r = 1;
    a = norm(a);
    while (e > 0) {
        if (e & 1) r = r * a % P;
        a = a * a % P;
        e >>= 1;
    }
    return r;
}

i64 quotient(i64 a, i64 b) {
    return norm(a) * modpow(b, P - 2) % P;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    i64 N, M;
    std::cin >> N >> M;
    if (norm(M + 1) == 0) {
        std::cout << norm((N & 1) ? N - 1 : -(N - 1)) << '\n';
        return 0;
    }
    i64 numerator = norm(modpow(M, N) + norm(M));
    std::cout << quotient(numerator, M + 1) << '\n';
    return 0;
}
0