結果

問題 No.2699 Simple Math (Returned)
ユーザー inkyamaninkyaman
提出日時 2024-03-29 21:46:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,025 ms / 2,000 ms
コード長 1,404 bytes
コンパイル時間 1,138 ms
コンパイル使用メモリ 116,772 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-29 21:46:54
合計ジャッジ時間 12,216 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 762 ms
6,676 KB
testcase_02 AC 769 ms
6,676 KB
testcase_03 AC 652 ms
6,676 KB
testcase_04 AC 1,025 ms
6,676 KB
testcase_05 AC 775 ms
6,676 KB
testcase_06 AC 862 ms
6,676 KB
testcase_07 AC 903 ms
6,676 KB
testcase_08 AC 905 ms
6,676 KB
testcase_09 AC 875 ms
6,676 KB
testcase_10 AC 882 ms
6,676 KB
testcase_11 AC 895 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <iomanip>
#include <climits>
#include <functional>
#include <cassert>
#include <tuple>
using namespace std;
using ll = long long;

int T;
ll mod = 998244353;

//ループの回数は適宜修正
ll power(ll a, ll b, ll m) {
    ll p = a, ans = 1;
    for(int i = 0; i < 60; i++) {
        ll wari = (1LL << i);
        if((b / wari) % 2 == 1) {
            ans = (ans * p) % m;
        }
        p = (p * p) % m;
    }
    return ans;
}

ll division(ll a, ll b, ll m) {
    return ((a % m) * power(b, m-2, m)) % m;
}

int main() {

    cin >> T;
    while(T--) {
        ll N, M;
        cin >> N >> M;
        if(N <= M) {
            ll ans = power(10,N,mod);
            ans = (ans-1+mod)%mod;
            cout << ans << endl;
        } else {
            ll r = N%(2*M);
            ll ans;
            if(r < M) {
                ans = power(10,r,mod);
                ans = (ans-1+mod)%mod;
            } else {
                ll a = power(10,M,mod);
                a = (a-1+mod)%mod;
                ll b = power(10,r-M,mod);
                b = (b-1+mod)%mod;
                ans = (a-b+mod)%mod;
            }
            cout << ans << endl;
        }
    }

}

0