結果

問題 No.2452 Incline
ユーザー sotanishysotanishy
提出日時 2023-09-01 21:39:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 207 ms / 2,000 ms
コード長 452 bytes
コンパイル時間 552 ms
コンパイル使用メモリ 87,200 KB
実行使用メモリ 78,508 KB
最終ジャッジ日時 2023-09-01 21:39:18
合計ジャッジ時間 3,201 ms
ジャッジサーバーID
(参考情報)
judge13 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,512 KB
testcase_01 AC 71 ms
71,208 KB
testcase_02 AC 72 ms
71,240 KB
testcase_03 AC 192 ms
78,172 KB
testcase_04 AC 207 ms
77,980 KB
testcase_05 AC 206 ms
78,508 KB
testcase_06 AC 153 ms
77,668 KB
testcase_07 AC 197 ms
77,664 KB
testcase_08 AC 144 ms
77,500 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

mod = 998244353
T = int(input())
for _ in range(T):
    N, M, L, R = map(int, input().split())
    ans = 0

    # d=0
    ans += R-L+1

    # d>0
    d1 = (L+N-2)//(N-1)
    d2 = R//(N-1)
    ans += (R-L+1)*(d1-1)+(R-(N-1)*d1+1 + R-(N-1)*d2+1)*(d2-d1+1)//2

    # d<0
    d1 = (M-R+N-2)//(N-1)
    d2 = (M-L+1)//(N-1)
    ans += (R-L+1)*(d1-1)+(M-L-(N-1)*d1+1 + M-L-(N-1)*d2+1)*(d2-d1+1)//2

    print(ans % mod)
0