結果

問題 No.2699 Simple Math (Returned)
ユーザー tnakao0123tnakao0123
提出日時 2024-04-29 22:59:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 134 ms / 2,000 ms
コード長 1,715 bytes
コンパイル時間 336 ms
コンパイル使用メモリ 45,312 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-29 22:59:29
合計ジャッジ時間 4,226 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 59 ms
5,376 KB
testcase_02 AC 108 ms
5,376 KB
testcase_03 AC 60 ms
5,376 KB
testcase_04 AC 134 ms
5,376 KB
testcase_05 AC 121 ms
5,376 KB
testcase_06 AC 87 ms
5,376 KB
testcase_07 AC 122 ms
5,376 KB
testcase_08 AC 120 ms
5,376 KB
testcase_09 AC 120 ms
5,376 KB
testcase_10 AC 119 ms
5,376 KB
testcase_11 AC 119 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2699.cc:  No.2699 Simple Math (Returned) - yukicoder
 */

#include<cstdio>
#include<algorithm>
 
using namespace std;

/* constant */

const int MOD = 998244353;

/* typedef */

template<const int MOD>
struct MI {
  int v;
  MI(): v() {}
  MI(int _v): v(_v % MOD) { if (v < 0) v += MOD; }
  MI(long long _v): v(_v % MOD) { if (v < 0) v += MOD; }

  explicit operator int() const { return v; }
  
  MI operator+(const MI m) const { return MI(v + m.v); }
  MI operator-(const MI m) const { return MI(v + MOD - m.v); }
  MI operator*(const MI m) const { return MI((long long)v * m.v); }

  MI &operator+=(const MI m) { return (*this = *this + m); }
  MI &operator-=(const MI m) { return (*this = *this - m); }
  MI &operator*=(const MI m) { return (*this = *this * m); }

  bool operator==(const MI m) const { return v == m.v; }
  bool operator!=(const MI m) const { return v != m.v; }

  MI pow(int n) const {  // a^n % MOD
    MI pm = 1, a = *this;
    while (n > 0) {
      if (n & 1) pm *= a;
      a *= a;
      n >>= 1;
    }
    return pm;
  }

  MI inv() const { return pow(MOD - 2); }
  MI operator/(const MI m) const { return *this * m.inv(); }
  MI &operator/=(const MI m) { return (*this = *this / m); }
};

using mi = MI<MOD>;

/* global variables */

/* subroutines */

/* main */

int main() {
  int tn;
  scanf("%d", &tn);

  while (tn--) {
    int n, m;
    scanf("%d%d", &n, &m);

    int m2 = m * 2, r = n % m2;
    mi p;
    if (r <= m)
      p = mi(10).pow(r) - 1;
    else
      p = (mi(10).pow(m * 2 - r) - 1) * mi(10).pow(r - m);
    // 6,4->999999%10001->999999%110011->9900
    // 6,5->999999%100001->99990
    
    printf("%d\n", (int)p);
  }
  
  return 0;
}
0