結果

問題 No.2699 Simple Math (Returned)
ユーザー InTheBloomInTheBloom
提出日時 2024-03-29 21:44:07
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 507 ms / 2,000 ms
コード長 1,212 bytes
コンパイル時間 876 ms
コンパイル使用メモリ 78,448 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-29 21:44:15
合計ジャッジ時間 7,863 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 390 ms
6,676 KB
testcase_02 AC 484 ms
6,676 KB
testcase_03 AC 387 ms
6,676 KB
testcase_04 AC 507 ms
6,676 KB
testcase_05 AC 497 ms
6,676 KB
testcase_06 AC 453 ms
6,676 KB
testcase_07 AC 493 ms
6,676 KB
testcase_08 AC 489 ms
6,676 KB
testcase_09 AC 487 ms
6,676 KB
testcase_10 AC 491 ms
6,676 KB
testcase_11 AC 488 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cassert>

using namespace std;
using ll = long long;

ll mod_pow (ll a, ll x, const ll MOD) {
    assert(1 <= MOD);
    assert(0 <= x);
    a %= MOD; if (a < 0) a += MOD;

    ll res = 1;
    while (0 < x) {
        if (0 < (x & 1)) {
            res *= a;
            res %= MOD;
        }
        a *= a;
        a %= MOD;
        x >>= 1;
    }

    return res;
}

void solve (int N, int M) {
    const ll MOD = 998244353;

    if (N <= M) {
        ll ans = mod_pow(10, N, MOD) - 1;
        if (ans < 0) ans += MOD;

        cout << ans << "\n";
        return;
    }

    int width = N % (2 * M);
    if (width == 0) {
        cout << 0 << "\n";
        return;
    }

    if (width < M + 1) {
        ll ans = mod_pow(10, width, MOD) - 1;
        if (ans < 0) ans += MOD;
        cout << ans << "\n";
        return;
    }

    int zero = width - (M + 1) + 1;
    int nine = width - 2 * zero;

    ll ans = mod_pow(10, nine, MOD) - 1;
    if (ans < 0) ans += MOD;
    ans *= mod_pow(10, zero, MOD);
    ans %= MOD;

    cout << ans << "\n";
}

int main () {
    int T; cin >> T;

    for (int _ = 0; _ < T; _++) {
        int N, M; cin >> N >> M;
        solve(N, M);
    }
}
0