結果

問題 No.2452 Incline
ユーザー hiro1729hiro1729
提出日時 2023-09-01 22:49:59
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,329 ms / 2,000 ms
コード長 524 bytes
コンパイル時間 229 ms
コンパイル使用メモリ 10,800 KB
実行使用メモリ 7,960 KB
最終ジャッジ日時 2023-09-01 22:50:08
合計ジャッジ時間 8,633 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,908 KB
testcase_01 AC 16 ms
7,772 KB
testcase_02 AC 15 ms
7,960 KB
testcase_03 AC 1,329 ms
7,828 KB
testcase_04 AC 1,191 ms
7,748 KB
testcase_05 AC 1,131 ms
7,832 KB
testcase_06 AC 1,276 ms
7,820 KB
testcase_07 AC 1,177 ms
7,912 KB
testcase_08 AC 1,065 ms
7,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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
        if y_max < m: break
        n, b, m, a = y_max // m, y_max % m, a, m
    return ans  
for _ in range(int(input())):
	n, m, l, r = map(int, input().split())
	c = 0
	c += floor_sum(m + 1, n - 1, -1, r)
	c -= floor_sum(m + 1, n - 1, -1, l - 1)
	print(c % 998244353)
0