結果

問題 No.2699 Simple Math (Returned)
ユーザー Magentor
提出日時 2025-08-11 15:31:25
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 324 ms / 2,000 ms
コード長 909 bytes
コンパイル時間 3,171 ms
コンパイル使用メモリ 276,088 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-08-11 15:31:33
合計ジャッジ時間 8,345 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
const int64 MOD = 998244353;

int64 modpow(int64 a, long long e, int64 mod){
    int64 r = 1 % mod;
    a %= mod;
    while(e){
        if(e & 1) r = (__int128)r * a % mod;
        a = (__int128)a * a % mod;
        e >>= 1;
    }
    return r;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    if(!(cin >> T)) return 0;
    while(T--){
        long long N, M;
        cin >> N >> M;
        long long q = N / M;
        long long r = N % M;
        int64 pow_r = modpow(10, r, MOD);
        int64 ans;
        if((q & 1) == 0){
            ans = (pow_r - 1) % MOD;
            if(ans < 0) ans += MOD;
        } else {
            int64 pow_M = modpow(10, M, MOD);
            ans = (pow_M - pow_r) % MOD;
            if(ans < 0) ans += MOD;
        }
        cout << ans << '\n';
    }
    return 0;
}
0