結果

問題 No.2324 Two Countries within UEC
ユーザー Ryoga.exeRyoga.exe
提出日時 2023-05-28 16:38:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 255 ms / 2,000 ms
コード長 807 bytes
コンパイル時間 2,014 ms
コンパイル使用メモリ 199,144 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-09 06:18:37
合計ジャッジ時間 9,317 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 235 ms
4,384 KB
testcase_01 AC 249 ms
4,380 KB
testcase_02 AC 45 ms
4,384 KB
testcase_03 AC 184 ms
4,380 KB
testcase_04 AC 213 ms
4,380 KB
testcase_05 AC 47 ms
4,380 KB
testcase_06 AC 84 ms
4,380 KB
testcase_07 AC 39 ms
4,380 KB
testcase_08 AC 179 ms
4,380 KB
testcase_09 AC 189 ms
4,380 KB
testcase_10 AC 250 ms
4,380 KB
testcase_11 AC 240 ms
4,380 KB
testcase_12 AC 76 ms
4,380 KB
testcase_13 AC 74 ms
4,384 KB
testcase_14 AC 45 ms
4,380 KB
testcase_15 AC 40 ms
4,380 KB
testcase_16 AC 168 ms
4,380 KB
testcase_17 AC 109 ms
4,384 KB
testcase_18 AC 50 ms
4,380 KB
testcase_19 AC 250 ms
4,384 KB
testcase_20 AC 33 ms
4,384 KB
testcase_21 AC 163 ms
4,380 KB
testcase_22 AC 213 ms
4,380 KB
testcase_23 AC 67 ms
4,380 KB
testcase_24 AC 174 ms
4,384 KB
testcase_25 AC 255 ms
4,384 KB
testcase_26 AC 192 ms
4,384 KB
testcase_27 AC 205 ms
4,384 KB
testcase_28 AC 191 ms
4,384 KB
testcase_29 AC 186 ms
4,504 KB
testcase_30 AC 189 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 2 ms
4,384 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 1 ms
4,384 KB
testcase_35 AC 1 ms
4,384 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 2 ms
4,384 KB
testcase_38 AC 1 ms
4,384 KB
testcase_39 AC 2 ms
4,384 KB
testcase_40 AC 2 ms
4,384 KB
testcase_41 AC 2 ms
4,384 KB
testcase_42 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

inline constexpr long long ModInv(long long a, const long long p) noexcept {
    long long b = p, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; std::swap(a, b);
        u -= t * v; std::swap(u, v);
    }
    u %= p; 
    if (u < 0) u += p;
    return u;
}

inline constexpr long long mod(const long long a, const long long m) noexcept {
    return (a % m + m) % m;
}

int main() {
    long long n, m, p, q;
    cin >> n >> m >> p >> q;
    while (q--) {
        long long x, f;
        cin >> x >> f;
        if (x % p == 0) {
            cout << (f == 0 ? m : 0) << endl;
        }
        else {
            auto y = mod((mod(f, p) * ModInv(x, p)) - 1, p);
            cout << m / p + (y <= mod(m - 1, p)) << endl;
	}
    }
}
0