結果

問題 No.2452 Incline
ユーザー Carpenters-CatCarpenters-Cat
提出日時 2023-09-01 21:52:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,010 ms / 2,000 ms
コード長 468 bytes
コンパイル時間 405 ms
コンパイル使用メモリ 87,216 KB
実行使用メモリ 85,876 KB
最終ジャッジ日時 2023-09-01 21:52:13
合計ジャッジ時間 5,117 ms
ジャッジサーバーID
(参考情報)
judge16 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,244 KB
testcase_01 AC 71 ms
71,160 KB
testcase_02 AC 72 ms
71,244 KB
testcase_03 AC 484 ms
79,204 KB
testcase_04 AC 562 ms
79,536 KB
testcase_05 AC 1,010 ms
85,876 KB
testcase_06 AC 374 ms
78,472 KB
testcase_07 AC 451 ms
78,648 KB
testcase_08 AC 410 ms
79,236 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

T = int(input())
m = 998244353
def calcSum(N, M, X) :
	N -= 1
	q1 = M // N
	r1 = M % N
	q2 = X // N
	r2 = X % N
	ri = min(r1, r2)
	ra = max(r1, r2)
	ans = (ri + 1) * (q1 + 1) * (q2 + 1)
	ans %= m
	if r1 < r2 :
		ans += (r2 - r1) * q1 * (q2 + 1)
	else :
		ans += (r1 - r2) * (q1 + 1) * q2
	ans %= m
	ans += (N - 1 - ra) * q2 * q1
	ans %= m
	return ans
for _ in range(T) :
	N, M, L, R = map(int, input().split())
	print((m + calcSum(N, M, R) - calcSum(N, M, L - 1)) % m)
0