結果

問題 No.2452 Incline
ユーザー 👑 kakel-sankakel-san
提出日時 2023-09-01 22:34:08
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 367 ms / 2,000 ms
コード長 1,161 bytes
コンパイル時間 1,639 ms
コンパイル使用メモリ 66,044 KB
実行使用メモリ 32,424 KB
最終ジャッジ日時 2023-09-01 22:34:14
合計ジャッジ時間 5,399 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
21,944 KB
testcase_01 AC 63 ms
22,020 KB
testcase_02 AC 64 ms
21,800 KB
testcase_03 AC 367 ms
32,308 KB
testcase_04 AC 338 ms
32,424 KB
testcase_05 AC 301 ms
32,412 KB
testcase_06 AC 325 ms
29,576 KB
testcase_07 AC 304 ms
28,288 KB
testcase_08 AC 269 ms
30,300 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static int NN => int.Parse(ReadLine());
    static long[] NList => ReadLine().Split().Select(long.Parse).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var t = NN;
        var ans = new long[t];
        for (var u = 0; u < t; ++u)
        {
            var c = NList;
            var (n, m, l, r) = (c[0], c[1], c[2], c[3]);
            ans[u] = Incline(n, m, l, r);
        }
        WriteLine(string.Join("\n", ans));
    }
    static readonly int mod = 998_244_353;
    static long Incline(long n, long m, long l, long r)
    {
        var ans = F(n, m, r);
        if (l > 0) ans = (ans + mod - F(n, m, l - 1)) % mod;
        return ans;
    }
    static long F(long n, long m, long r)
    {
        return (m / (n - 1) % mod * (r % mod + 1) % mod + G(n, m, r)) % mod;
    }
    static long G(long n, long m, long r)
    {
        return (r / (n - 1) % mod * (m % (n - 1) + 1) % mod + Math.Min(r % (n - 1), m % (n - 1)) + 1) % mod;
    }
}
0