結果
問題 | No.2324 Two Countries within UEC |
ユーザー |
![]() |
提出日時 | 2023-05-28 13:50:50 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 288 ms / 2,000 ms |
コード長 | 770 bytes |
コンパイル時間 | 4,202 ms |
コンパイル使用メモリ | 250,004 KB |
最終ジャッジ日時 | 2025-02-13 10:22:47 |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 41 |
ソースコード
#include<bits/stdc++.h>#include<atcoder/all>using namespace std;using namespace atcoder;typedef modint998244353 mint;typedef long long ll;ll mod_pow(ll x, ll m, int P){ll ret = 1;ll tmp = x;while (m > 0){if (m&1){ret = ret * tmp % P;}m >>= 1;tmp = tmp * tmp % P;}return ret;}int main(){ll n, m, p; cin >> n >> m >> p;int q; cin >> q;ll base = m / p;ll amari = m % p;for (int i=0; i<q; i++){ll x, f; cin >> x >> f;if (x % p == 0){if (f == 0){cout << m << "\n";}else{cout << 0 << "\n";}}else{ll tar = mod_pow(x % p, p-2, (int)p) * f % p;if (tar == 0){cout << base << "\n";}else if (tar <= amari){cout << base + 1 << "\n";}else{cout << base << "\n";}}}}