結果

問題 No.2324 Two Countries within UEC
ユーザー ja14378ja14378
提出日時 2023-05-28 14:19:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 220 ms / 2,000 ms
コード長 871 bytes
コンパイル時間 4,770 ms
コンパイル使用メモリ 259,804 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-09 06:12:11
合計ジャッジ時間 10,728 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 209 ms
4,380 KB
testcase_01 AC 219 ms
4,380 KB
testcase_02 AC 40 ms
4,376 KB
testcase_03 AC 158 ms
4,380 KB
testcase_04 AC 183 ms
4,380 KB
testcase_05 AC 42 ms
4,380 KB
testcase_06 AC 74 ms
4,380 KB
testcase_07 AC 34 ms
4,376 KB
testcase_08 AC 157 ms
4,380 KB
testcase_09 AC 161 ms
4,376 KB
testcase_10 AC 219 ms
4,380 KB
testcase_11 AC 209 ms
4,376 KB
testcase_12 AC 65 ms
4,376 KB
testcase_13 AC 66 ms
4,376 KB
testcase_14 AC 40 ms
4,380 KB
testcase_15 AC 34 ms
4,376 KB
testcase_16 AC 148 ms
4,376 KB
testcase_17 AC 96 ms
4,376 KB
testcase_18 AC 43 ms
4,380 KB
testcase_19 AC 215 ms
4,376 KB
testcase_20 AC 28 ms
4,376 KB
testcase_21 AC 135 ms
4,380 KB
testcase_22 AC 177 ms
4,376 KB
testcase_23 AC 55 ms
4,380 KB
testcase_24 AC 143 ms
4,376 KB
testcase_25 AC 220 ms
4,376 KB
testcase_26 AC 173 ms
4,376 KB
testcase_27 AC 206 ms
4,376 KB
testcase_28 AC 169 ms
4,380 KB
testcase_29 AC 170 ms
4,380 KB
testcase_30 AC 171 ms
4,380 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 2 ms
4,384 KB
testcase_34 AC 2 ms
4,384 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 1 ms
4,376 KB
testcase_39 AC 1 ms
4,384 KB
testcase_40 AC 1 ms
4,380 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using ll = long long;
#define MOD 1000000007
#define Mod 998244353
const int MAX = 1000000005;
const long long INF = 1000000000000000005LL;
using namespace std;
using namespace atcoder;

ll modpow(ll a, ll n, ll m) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % m;
		a = a * a % m;
		n >>= 1;
	}
	return res;
}

ll modinv(ll a, ll m) {
	return modpow(a, m-2, m);
}

int main() {
    ios::sync_with_stdio(0);cin.tie();
    int N, M, P, Q;
    cin >> N >> M >> P >> Q;
    while (Q--) {
        int x, f;
        cin >> x >> f;
        int a = modinv(x, P) * f % P;
        if (x % P == 0) {
            cout << (f == 0 ? M : 0) << endl;
            continue;
        }
        if (M < a) {
            cout << 0 << endl;
        } else {
            cout << (M - a)/P + 1 - (a == 0) << endl;
        }
    }
}
0