結果

問題 No.2452 Incline
ユーザー ゼットゼット
提出日時 2023-09-01 21:47:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 520 ms / 2,000 ms
コード長 561 bytes
コンパイル時間 429 ms
コンパイル使用メモリ 87,260 KB
実行使用メモリ 78,552 KB
最終ジャッジ日時 2023-09-01 21:47:56
合計ジャッジ時間 4,573 ms
ジャッジサーバーID
(参考情報)
judge12 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,500 KB
testcase_01 AC 74 ms
71,248 KB
testcase_02 AC 73 ms
71,516 KB
testcase_03 AC 444 ms
78,496 KB
testcase_04 AC 480 ms
77,832 KB
testcase_05 AC 520 ms
78,244 KB
testcase_06 AC 480 ms
78,468 KB
testcase_07 AC 492 ms
78,080 KB
testcase_08 AC 394 ms
78,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

Q=int(input())
mod=998244353
def floor_sum(n, m, a, b):
    ans = 0
    while True:
        if a >= m or a < 0:
            ans += n * (n - 1) * (a // m) // 2
            a %= m
        if b >= m or b < 0:
            ans += n * (b // m)
            b %= m
        y_max = a * n + b
        ans%=mod
        if y_max < m: break
        n, b, m, a = y_max // m, y_max % m, a, m
    return ans 
mod=998244353
for i in range(Q):
  N,M,L,R=map(int,input().split())
  result=floor_sum(M+1,N-1,1,R-M)
  result-=floor_sum(M+1,N-1,1,L-M-1)
  result%=mod
  print(result)
0