結果

問題 No.2324 Two Countries within UEC
ユーザー kobaryo222
提出日時 2023-05-28 14:03:27
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,173 bytes
コンパイル時間 2,083 ms
コンパイル使用メモリ 195,156 KB
最終ジャッジ日時 2025-02-13 10:43:01
ジャッジサーバーID
(参考情報)
judge1 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 30 WA * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF (1LL << 60)
#define all(v) (v).begin(), (v).end()

template <class T>
void chmin(T &a, T b) {
    if (a > b) a = b;
}

template <class T>
void chmax(T &a, T b) {
    if (a < b) a = b;
}
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^-1
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;
}

int main() {
    ll N, M, P, Q;
    cin >> N >> M >> P >> Q;
    vector<ll> x(Q), f(Q);

    rep(i, Q) {
        cin >> x[i] >> f[i];
        ll ans = 0;
        ll tx = f[i] * modinv(x[i], P) % P;
        if (tx == 0) tx = P;
        // cout << tx << endl;
        if (M >= tx) {
            ans++;
            ans += (M - tx) / P;
        }
        cout << ans << endl;
    }
}
0