結果

問題 No.3799 1 + 6 = 7 (Another version)
ユーザー 👑 potato167
提出日時 2026-11-13 09:44:05
言語 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
結果
TLE  
実行時間 -
コード長 822 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,549 ms
コンパイル使用メモリ 213,984 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-11-13 22:08:23
合計ジャッジ時間 12,224 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 3
other AC * 20 TLE * 2 -- * 14
権限があれば一括ダウンロードができます

ソースコード

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) {
	if (e == 0) return 1;
	if (e % (P - 1) == 0) return (a % P == 0 ? 0 : 1);
	e %= (P - 1);
    i64 r = 1;
    a = norm(a);
    while (e > 0) {
        r = r * a % P;
        e --;
    }
    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 (M % P == P - 1) {
        std::cout << norm((N & 1) ? N - 1 : -(N - 1)) << '\n';
        return 0;
    }
    i64 numerator = norm(modpow(M, N) + (N & 1 ? -norm(M) : norm(M)));
    std::cout << quotient(numerator, M + 1) << '\n';
    return 0;
}
0