結果
問題 |
No.2324 Two Countries within UEC
|
ユーザー |
![]() |
提出日時 | 2023-06-29 01:41:55 |
言語 | C# (.NET 8.0.404) |
結果 |
AC
|
実行時間 | 435 ms / 2,000 ms |
コード長 | 1,618 bytes |
コンパイル時間 | 6,326 ms |
コンパイル使用メモリ | 166,620 KB |
実行使用メモリ | 182,580 KB |
最終ジャッジ日時 | 2024-07-05 18:12:34 |
合計ジャッジ時間 | 17,901 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 41 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (79 ms)。 MSBuild のバージョン 17.9.6+a4ecab324 (.NET) main -> /home/judge/data/code/bin/Release/net8.0/main.dll main -> /home/judge/data/code/bin/Release/net8.0/publish/
ソースコード
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; } } } }