結果

問題 No.2324 Two Countries within UEC
ユーザー 👑 kakel-sankakel-san
提出日時 2023-10-18 00:25:12
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 290 ms / 2,000 ms
コード長 1,390 bytes
コンパイル時間 8,041 ms
コンパイル使用メモリ 156,796 KB
実行使用メモリ 178,820 KB
最終ジャッジ日時 2023-10-18 00:25:30
合計ジャッジ時間 17,671 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 275 ms
57,984 KB
testcase_01 AC 286 ms
58,020 KB
testcase_02 AC 116 ms
38,188 KB
testcase_03 AC 241 ms
54,032 KB
testcase_04 AC 251 ms
57,072 KB
testcase_05 AC 121 ms
38,452 KB
testcase_06 AC 149 ms
42,748 KB
testcase_07 AC 112 ms
37,396 KB
testcase_08 AC 227 ms
56,672 KB
testcase_09 AC 227 ms
54,552 KB
testcase_10 AC 290 ms
58,008 KB
testcase_11 AC 270 ms
58,008 KB
testcase_12 AC 144 ms
41,424 KB
testcase_13 AC 146 ms
41,452 KB
testcase_14 AC 116 ms
38,120 KB
testcase_15 AC 112 ms
37,388 KB
testcase_16 AC 219 ms
51,900 KB
testcase_17 AC 170 ms
45,048 KB
testcase_18 AC 120 ms
38,532 KB
testcase_19 AC 287 ms
58,076 KB
testcase_20 AC 111 ms
36,620 KB
testcase_21 AC 176 ms
59,584 KB
testcase_22 AC 189 ms
59,744 KB
testcase_23 AC 120 ms
43,192 KB
testcase_24 AC 178 ms
61,632 KB
testcase_25 AC 282 ms
58,008 KB
testcase_26 AC 155 ms
61,556 KB
testcase_27 AC 155 ms
61,508 KB
testcase_28 AC 151 ms
61,520 KB
testcase_29 AC 149 ms
61,520 KB
testcase_30 AC 150 ms
61,512 KB
testcase_31 AC 78 ms
32,736 KB
testcase_32 AC 80 ms
32,744 KB
testcase_33 AC 81 ms
32,744 KB
testcase_34 AC 82 ms
32,744 KB
testcase_35 AC 81 ms
32,744 KB
testcase_36 AC 80 ms
32,744 KB
testcase_37 AC 79 ms
32,744 KB
testcase_38 AC 79 ms
32,744 KB
testcase_39 AC 79 ms
32,744 KB
testcase_40 AC 79 ms
32,744 KB
testcase_41 AC 79 ms
32,744 KB
testcase_42 AC 82 ms
178,820 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (103 ms)。
MSBuild のバージョン 17.7.3+8ec440e68 (.NET)
  main -> /home/judge/data/code/bin/Release/net7.0/main.dll
  main -> /home/judge/data/code/bin/Release/net7.0/publish/

ソースコード

diff #

using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static int NN => int.Parse(ReadLine());
    static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var c = NList;
        var (n, m, p, q) = (c[0], c[1], c[2], c[3]);
        var ans = new int[q];
        for (var u = 0; u < q; ++u)
        {
            c = NList;
            ans[u] = Country(m, c[0], c[1], p);
        }
        WriteLine(string.Join("\n", ans));
    }
    static int Country(int m, int x, int f, int p)
    {
        if (x % p == 0)
        {
            if (f == 0) return m;
            else return 0;
        }
        var revx = Exp(x, p - 2, p);
        var ex = (int)(f * revx % p);
        if (ex > m) return 0;
        return (m - ex) / p + (ex > 0 ? 1 : 0);
    }
    static int GCD(int a, int b)
    {
        if (a < b) return GCD(b, a);
        if (a % b == 0) return b;
        return GCD(b, a % b);
    }
    static long Exp(long n, long k, int mod)
    {
        if (k == 0) return 1;
        if (k == 1) return n % mod;
        var half = Exp(n, k / 2, mod);
        var result = (half * half) % mod;
        return ((k % 2) == 0) ? result : ((result * n) % mod);
    }
}
0