結果
| 問題 | 
                            No.2699 Simple Math (Returned)
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2024-03-29 21:44:42 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,730 bytes | 
| コンパイル時間 | 2,436 ms | 
| コンパイル使用メモリ | 194,568 KB | 
| 最終ジャッジ日時 | 2025-02-20 14:54:11 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 5 WA * 6 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = n; i > 0; --i)
#define bitrep(i, n) for (ll i = 0; i < (1 << n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define yesNo(b) ((b) ? "Yes" : "No")
using ll = long long;
using ull = unsigned long long;
using ld = long double;
string alphabet = "abcdefghijklmnopqrstuvwxyz";
string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const double pi = 3.141592653589793;
ll smallMOD = 998244353;
ll bigMOD = 1000000007;
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
ll repeated_squaring(ll x, ll y, ll z = smallMOD)
{
    ll ans = 1;
    bitset<64> bits(y);
    string bit_str = bits.to_string();
    reverse(all(bit_str));
    rep(i, 64)
    {
        if (bit_str[i] == '1')
            ans = ans * x % z;
        x = x * x % z;
    }
    return ans;
}
int main()
{
    ll t;
    cin >> t;
    rep(i, t)
    {
        ll n, m;
        cin >> n >> m;
        if (n % (2 * m) == 0)
        {
            cout << 0 << endl;
        }
        else
        {
            if (n % (2 * m) <= m)
            {
                ll n10 = repeated_squaring(10, (n + m - 1) % m + 1);
                n10--;
                n10 %= smallMOD;
                cout << n10 << endl;
            }
            else
            {
                // 10^m-10^(n%m)
                ll n10 = repeated_squaring(10, m);
                ll n10_ = repeated_squaring(10, n % m);
                n10 -= n10_;
                n10 %= smallMOD;
                cout << n10 << endl;
            }
        }
    }
    return 0;
}