結果
| 問題 |
No.2324 Two Countries within UEC
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-05-28 09:45:52 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 269 ms / 2,000 ms |
| コード長 | 1,536 bytes |
| コンパイル時間 | 1,040 ms |
| コンパイル使用メモリ | 114,112 KB |
| 最終ジャッジ日時 | 2025-02-13 09:32:25 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 41 |
ソースコード
#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;
}