結果

問題 No.2452 Incline
ユーザー ねしんねしん
提出日時 2024-07-16 18:00:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 604 ms / 2,000 ms
コード長 492 bytes
コンパイル時間 223 ms
コンパイル使用メモリ 82,132 KB
実行使用メモリ 77,440 KB
最終ジャッジ日時 2024-07-16 18:00:16
合計ジャッジ時間 5,996 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
52,096 KB
testcase_01 AC 39 ms
51,968 KB
testcase_02 AC 39 ms
52,272 KB
testcase_03 AC 604 ms
77,440 KB
testcase_04 AC 586 ms
76,544 KB
testcase_05 AC 539 ms
77,292 KB
testcase_06 AC 553 ms
76,672 KB
testcase_07 AC 555 ms
76,472 KB
testcase_08 AC 391 ms
76,920 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

T=int(input())
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 i in range(T):
	n,m,l,r=list(map(int,input().split()))
	print((floor_sum(m+1,n-1,-1,r)-floor_sum(m+1,n-1,-1,l-1))%998244353)
0