結果

問題 No.2452 Incline
ユーザー lloyzlloyz
提出日時 2023-09-02 01:51:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 666 ms / 2,000 ms
コード長 480 bytes
コンパイル時間 470 ms
コンパイル使用メモリ 87,008 KB
実行使用メモリ 81,948 KB
最終ジャッジ日時 2023-09-02 01:51:22
合計ジャッジ時間 5,416 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
71,380 KB
testcase_01 AC 65 ms
71,560 KB
testcase_02 AC 66 ms
71,244 KB
testcase_03 AC 582 ms
79,460 KB
testcase_04 AC 613 ms
80,952 KB
testcase_05 AC 596 ms
79,624 KB
testcase_06 AC 537 ms
79,384 KB
testcase_07 AC 666 ms
81,948 KB
testcase_08 AC 524 ms
79,284 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

mod = 998244353
def func(x, n):
    q, r = divmod(x, n - 1)
    ans = (n - 1) * q % mod * (q - 1) % mod * pow(2, mod - 2, mod) % mod
    ans += q * (r + 1) % mod
    ans %= mod
    return ans

for _ in range(int(input())):
    n, m, l, r = map(int, input().split())
    ans = (func(r, n) - func(l - 1, n)) % mod
    ans += (func(m - l, n) - func(m - r - 1, n)) % mod
    ans %= mod
    ans += (r - l + 1) % mod
    ans %= mod
    print(ans)
0