結果
| 問題 | 
                            No.3118 Increment or Multiply
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2025-03-20 12:16:08 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 54 ms / 2,000 ms | 
| コード長 | 660 bytes | 
| コンパイル時間 | 3,526 ms | 
| コンパイル使用メモリ | 250,564 KB | 
| 実行使用メモリ | 7,844 KB | 
| 最終ジャッジ日時 | 2025-04-12 16:42:54 | 
| 合計ジャッジ時間 | 5,410 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 35 | 
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using mint = modint998244353;
constexpr ll mod = 998244353;
constexpr ll twoinv = 499122177;
#define fast cin.tie(nullptr); ios_base::sync_with_stdio(false)
ll t,n,a;
mint s(ll x){
  if(a == 1){
  	mint ans = n;
  	ans *= n - 1;
  	ans /= 2;
  	return ans;
  }
  if(x <= 1) return 0;
  ll b = x / a,c = x - a * b;
  mint res = (c + 1);
  res *= b;
  mint pl = (x - b - 1);
  pl *= x - b;
  pl /= 2;
  return res + pl + s(b);
}
int main() {
	fast;
    cin >> t;
    while(t--){
        cin >> n >> a;
        cout << s(n).val() << endl;
    }
}