結果

問題 No.3118 Increment or Multiply
ユーザー Naru820
提出日時 2025-03-20 20:41:40
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 62 ms / 2,000 ms
コード長 648 bytes
コンパイル時間 4,451 ms
コンパイル使用メモリ 251,204 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-04-12 16:43:07
合計ジャッジ時間 6,450 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 || (x < a)){
  	mint ans = x;
  	ans *= x - 1;
  	ans /= 2;
  	return ans;
  }
  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;
    }
}
0