結果
問題 | No.2699 Simple Math (Returned) |
ユーザー |
|
提出日時 | 2024-03-29 21:44:07 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 449 ms / 2,000 ms |
コード長 | 1,212 bytes |
コンパイル時間 | 731 ms |
コンパイル使用メモリ | 78,720 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-09-30 15:46:44 |
合計ジャッジ時間 | 6,772 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 11 |
ソースコード
#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);}}