結果

問題 No.2324 Two Countries within UEC
ユーザー phocomphocom
提出日時 2023-05-28 09:45:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 247 ms / 2,000 ms
コード長 1,536 bytes
コンパイル時間 1,494 ms
コンパイル使用メモリ 117,204 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-09 06:00:43
合計ジャッジ時間 7,967 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 229 ms
4,380 KB
testcase_01 AC 243 ms
4,376 KB
testcase_02 AC 44 ms
4,380 KB
testcase_03 AC 179 ms
4,380 KB
testcase_04 AC 209 ms
4,380 KB
testcase_05 AC 47 ms
4,376 KB
testcase_06 AC 84 ms
4,380 KB
testcase_07 AC 38 ms
4,380 KB
testcase_08 AC 185 ms
4,380 KB
testcase_09 AC 185 ms
4,380 KB
testcase_10 AC 245 ms
4,384 KB
testcase_11 AC 239 ms
4,380 KB
testcase_12 AC 74 ms
4,384 KB
testcase_13 AC 74 ms
4,376 KB
testcase_14 AC 44 ms
4,376 KB
testcase_15 AC 39 ms
4,380 KB
testcase_16 AC 166 ms
4,376 KB
testcase_17 AC 104 ms
4,376 KB
testcase_18 AC 49 ms
4,380 KB
testcase_19 AC 247 ms
4,380 KB
testcase_20 AC 32 ms
4,380 KB
testcase_21 AC 160 ms
4,384 KB
testcase_22 AC 205 ms
4,380 KB
testcase_23 AC 65 ms
4,376 KB
testcase_24 AC 169 ms
4,380 KB
testcase_25 AC 239 ms
4,380 KB
testcase_26 AC 186 ms
4,380 KB
testcase_27 AC 203 ms
4,380 KB
testcase_28 AC 189 ms
4,376 KB
testcase_29 AC 186 ms
4,376 KB
testcase_30 AC 184 ms
4,376 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()

using namespace std;

constexpr int inf = 1 << 30;
constexpr long long llinf = 1LL << 62;
constexpr int mod = 998244353;  // 1000000007;

using ll = long long;

namespace phc {
long long modpow(long long a, long long n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
long long modinv(long long a, long long m) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}
long long gcd(long long a, long long b) { return b != 0 ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
}  // namespace phc

int main() {
  ll N, M, P, Q;
  cin >> N >> M >> P >> Q;
  REP(i, Q) {
    ll x, f;
    cin >> x >> f;
    if (x % P == 0) {
      cout << (f == 0 ? M : 0LL) << endl;
    } else {
      ll y = f * phc::modinv(x, P) % P;
      cout << ((M - y + (f != 0 ? P : 0LL)) / P) << endl;
    }
  }
  return 0;
}
0