結果

問題 No.3118 Increment or Multiply
ユーザー Naru820
提出日時 2025-04-05 16:36:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 203 ms / 2,000 ms
コード長 377 bytes
コンパイル時間 415 ms
コンパイル使用メモリ 82,684 KB
実行使用メモリ 78,088 KB
最終ジャッジ日時 2025-04-12 16:43:21
合計ジャッジ時間 6,605 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 998244353
twoinv = 499122177
n,a = 0,0
def f(x):
    if a == 1 or (x < a):
        ans = x * (x - 1) // 2
        return ans % mod
    b,c = x // a,x % a
    res = ((c + 1) * b) % mod
    pl = (x - b - 1) * (x - b)
    pl = (pl * twoinv) % mod
    return (res + pl + f(b)) % mod
t = int(input())
while t > 0:
    n,a = map(int, input().split())
    print(f(n))
    t -= 1
0