結果
問題 |
No.2699 Simple Math (Returned)
|
ユーザー |
|
提出日時 | 2024-05-01 23:38:37 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,277 bytes |
コンパイル時間 | 1,511 ms |
コンパイル使用メモリ | 167,544 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-22 07:50:09 |
合計ジャッジ時間 | 8,154 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 2 WA * 9 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)n; i++) using ll = long long int; #define MOD 998244353 int mod_pow(int x, int n) { int ret = 1; while (n > 0) { if ((n & 0x01) != 0) ret = (long long)ret * x % MOD; x = (long long)x * x % MOD; n >>= 1; } return ret; } int main() { int T; cin >> T; rep(i, T) { int N, M; cin >> N >> M; // 10^N - 1 = (10^M + 1)10^(N-M) - 10^(N-M) - 1 // = (10^M + 1)10^(N-M) - (10^(N-M) + 1) // (10^N - 1) % (10^M +1) = - (10^(N-M) + 1) / (10^M + 1) // 10^(N-M) + 1 = (10^M + 1)10^(N-2・M) - 10^(N-2・M) + 1 // = (10^M + 1)10^(N-2・M) - (10^(N-2・M) - 1) // (10^(N-M) + 1) % (10^M + 1) = - (10^(N-2・M) - 1) / (10^M + 1) // (10^N - 1) % (10^M + 1) = (10^(N-2・M) - 1) / (10^M + 1) // = (10^(N-2・M・k) - 1) / (10^M + 1) // N-2・M・k >= M ... ((10^(N-2・M・k) - 1) - (10^M + 1)) % MOD // N-2・M・k < M ... (10^(N-2・M・k) - 1) % MOD N %= 2*M; int ans; if (N >= M) { ans = (mod_pow(10, N) - mod_pow(10, N) - 2) % MOD; } else { ans = mod_pow(10, N) - 1; if (ans < 0) ans += MOD; } cout << ans << endl; } return 0; }