結果

問題 No.2324 Two Countries within UEC
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-06-03 23:56:29
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 289 ms / 2,000 ms
コード長 878 bytes
コンパイル時間 889 ms
コンパイル使用メモリ 105,508 KB
最終ジャッジ日時 2025-02-13 22:28:37
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>
#include <cassert>

using namespace std;
using ll = long long;

ll mod_exp(ll b, ll e, ll m){
    if (e > 0 && b == 0) return 0;
    ll ans = 1;
    b %= m;

    while (e > 0){
        if ((e & 1LL)) ans = (ans * b) % m;
        e = e >> 1LL;
        b = (b*b) % m;
    }

    return ans;
}

int main(){

    ll N, M, P, Q, x, f, y;
    cin >> N >> M >> P >> Q;
    for (int i=0; i<Q; i++){
        cin >> x >> f;
        if (x % P == 0){
            cout << (f == 0 ? M : 0) << endl;
        }
        else{
            y = (mod_exp(x, P-2, P) * f) % P;
            if (M < y) cout << 0 << endl;
            else cout << (M-y)/P+(f != 0) << endl;
        }
    }

    return 0;
}
0