結果
問題 | No.2324 Two Countries within UEC |
ユーザー |
![]() |
提出日時 | 2024-12-06 13:01:19 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 94 ms / 2,000 ms |
コード長 | 744 bytes |
コンパイル時間 | 1,881 ms |
コンパイル使用メモリ | 193,604 KB |
最終ジャッジ日時 | 2025-02-26 11:12:58 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 41 |
ソースコード
#include <bits/stdc++.h> using namespace std; void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } long long pow_mod(long long x, long long n, long long p) { long long res = 1; while (n > 0) { if (n % 2 == 1) { res = (res * x) % p; } x = (x * x) % p; n /= 2; } return res; } long long inv_mod(long long x, long long p) { return pow_mod(x, p - 2, p); } int main() { fast_io(); int n, m, p, q; cin >> n >> m >> p >> q; for (; q--;) { int x, f; cin >> x >> f; if (x % p == 0) { if (f == 0) cout << m << "\n"; else cout << 0 << "\n"; continue; } long long r = f * inv_mod(x, p) % p; if (r == 0) { cout << m / p << "\n"; } else { cout << (m - r + p) / p << "\n"; } } }