結果

問題 No.2452 Incline
ユーザー rlangevinrlangevin
提出日時 2024-03-28 00:03:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 390 ms / 2,000 ms
コード長 667 bytes
コンパイル時間 231 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 78,396 KB
最終ジャッジ日時 2024-03-28 00:04:03
合計ジャッジ時間 4,392 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,460 KB
testcase_01 AC 37 ms
53,460 KB
testcase_02 AC 37 ms
53,460 KB
testcase_03 AC 390 ms
78,396 KB
testcase_04 AC 373 ms
77,752 KB
testcase_05 AC 308 ms
78,028 KB
testcase_06 AC 339 ms
78,268 KB
testcase_07 AC 376 ms
77,624 KB
testcase_08 AC 183 ms
76,196 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

# https://qiita.com/AkariLuminous/items/3e2c80baa6d5e6f3abe9#4-floor_sum
def floor_sum(n, m, a, b=0):
    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
        if y_max < m: break
        n, b, m, a = y_max // m, y_max % m, a, m
    return ans


T = int(input())
mod = 998244353
for _ in range(T):
    N, M, L, R = map(int, input().split())
    ans = M + 1 + floor_sum(M + 1, N - 1, -1, R) - floor_sum(M + 1, N - 1, -1, L + N - 2)
    print(ans % mod)
0