結果

問題 No.2452 Incline
ユーザー minimumminimum
提出日時 2023-09-01 21:45:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 835 ms / 2,000 ms
コード長 496 bytes
コンパイル時間 354 ms
コンパイル使用メモリ 87,016 KB
実行使用メモリ 85,152 KB
最終ジャッジ日時 2023-09-01 21:45:44
合計ジャッジ時間 5,193 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,420 KB
testcase_01 AC 69 ms
71,384 KB
testcase_02 AC 69 ms
71,428 KB
testcase_03 AC 493 ms
79,444 KB
testcase_04 AC 586 ms
79,448 KB
testcase_05 AC 835 ms
85,152 KB
testcase_06 AC 368 ms
78,784 KB
testcase_07 AC 441 ms
78,804 KB
testcase_08 AC 371 ms
78,964 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 998244353

def f(N, x, y):
    if x < 0 or y < 0 or N < 1:
        return 0
    if x % (N - 1) > y % (N - 1):
        return f(N, y, x)
    ans = 0
    M = N - 1
    ans += (x // M + 1) * (y // M + 1) * (x % M + 1)
    ans += (x // M) * (y // M + 1) * (y % M - x % M)
    ans += (x // M) * (y // M) * (M - 1 - y % M)
    return ans % MOD

def solve():
    N, M, L, R = map(int, input().split())
    print((f(N, M, R) - f(N, M, L - 1)) % MOD)

T = int(input())
for _ in range(T):
    solve()
0