結果
| 問題 |
No.2324 Two Countries within UEC
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-05-28 14:19:35 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 209 ms / 2,000 ms |
| コード長 | 871 bytes |
| コンパイル時間 | 4,144 ms |
| コンパイル使用メモリ | 251,144 KB |
| 最終ジャッジ日時 | 2025-02-13 11:14:34 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 41 |
ソースコード
#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;
}
}
}