結果

問題 No.2324 Two Countries within UEC
ユーザー AdamantiteAdamantite
提出日時 2023-06-29 01:41:55
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 562 ms / 2,000 ms
コード長 1,618 bytes
コンパイル時間 7,824 ms
コンパイル使用メモリ 145,772 KB
実行使用メモリ 163,264 KB
最終ジャッジ日時 2023-09-19 05:55:45
合計ジャッジ時間 21,571 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 522 ms
46,516 KB
testcase_01 AC 561 ms
47,060 KB
testcase_02 AC 139 ms
32,092 KB
testcase_03 AC 420 ms
42,588 KB
testcase_04 AC 484 ms
44,544 KB
testcase_05 AC 145 ms
32,272 KB
testcase_06 AC 219 ms
37,168 KB
testcase_07 AC 130 ms
31,596 KB
testcase_08 AC 429 ms
44,600 KB
testcase_09 AC 424 ms
42,704 KB
testcase_10 AC 562 ms
47,120 KB
testcase_11 AC 527 ms
47,352 KB
testcase_12 AC 207 ms
34,244 KB
testcase_13 AC 198 ms
34,388 KB
testcase_14 AC 139 ms
33,720 KB
testcase_15 AC 127 ms
33,644 KB
testcase_16 AC 388 ms
41,192 KB
testcase_17 AC 269 ms
36,480 KB
testcase_18 AC 144 ms
32,120 KB
testcase_19 AC 555 ms
47,444 KB
testcase_20 AC 112 ms
31,132 KB
testcase_21 AC 347 ms
44,040 KB
testcase_22 AC 458 ms
47,968 KB
testcase_23 AC 175 ms
34,860 KB
testcase_24 AC 369 ms
45,476 KB
testcase_25 AC 551 ms
47,180 KB
testcase_26 AC 384 ms
46,316 KB
testcase_27 AC 384 ms
47,476 KB
testcase_28 AC 382 ms
46,328 KB
testcase_29 AC 382 ms
48,480 KB
testcase_30 AC 380 ms
46,424 KB
testcase_31 AC 51 ms
28,700 KB
testcase_32 AC 52 ms
28,552 KB
testcase_33 AC 52 ms
28,676 KB
testcase_34 AC 52 ms
28,636 KB
testcase_35 AC 51 ms
28,788 KB
testcase_36 AC 52 ms
28,884 KB
testcase_37 AC 53 ms
28,724 KB
testcase_38 AC 52 ms
30,792 KB
testcase_39 AC 51 ms
28,692 KB
testcase_40 AC 52 ms
28,856 KB
testcase_41 AC 53 ms
28,608 KB
testcase_42 AC 52 ms
163,264 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  Determining projects to restore...
  Restored /home/judge/data/code/main.csproj (in 126 ms).
.NET 向け Microsoft (R) Build Engine バージョン 17.0.0-preview-21470-01+cb055d28f
Copyright (C) Microsoft Corporation.All rights reserved.

  プレビュー版の .NET を使用しています。https://aka.ms/dotnet-core-preview をご覧ください
  main -> /home/judge/data/code/bin/Release/net6.0/main.dll
  main -> /home/judge/data/code/bin/Release/net6.0/publish/

ソースコード

diff #

using System;

namespace No02324_TwoCountriesWithinUEC
{
    internal class Program
    {
        static void Main(string[] args) {
            string[] param = Console.ReadLine().Split(' ');
            int n = int.Parse(param[0]);
            int m = int.Parse(param[1]);
            int p = int.Parse(param[2]);
            int q = int.Parse(param[3]);

            int[] result = new int[q];
            for (int i = 0; i < q; i++) {
                string[] param2 = Console.ReadLine().Split(' ');
                int x = int.Parse(param2[0]);
                int f = int.Parse(param2[1]);

                int xMod = x % p;
                if (xMod == 0) {
                    if (f == 0) {
                        result[i] = m;
                    } else {
                        result[i] = 0;
                    }
                } else {
                    long y = f * RepPow(x, p - 2, p) % p;
                    if(y == 0) {
                        y += p;
                    }
                    if(y <= m) {
                        result[i] = (int)(m - y) / p + 1;
                    }
                }
            }
            for (int i = 0; i < q; i++) {
                Console.WriteLine(result[i]);
            }
        }

        //x^p % mod
        static long RepPow(long n, long p, int mod) {
            if (p == 0) {
                return 1;
            }
            if (p % 2 == 0) {
                var x = RepPow(n, p / 2, mod);
                return (x * x) % mod;
            } else {
                return RepPow(n, p - 1, mod) * n % mod;
            }
        }
    }
}
0