結果

問題 No.2324 Two Countries within UEC
ユーザー 0214sh70214sh7
提出日時 2023-05-28 15:52:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 272 ms / 2,000 ms
コード長 1,380 bytes
コンパイル時間 2,311 ms
コンパイル使用メモリ 198,020 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-09 06:16:52
合計ジャッジ時間 9,519 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 258 ms
4,376 KB
testcase_01 AC 269 ms
4,376 KB
testcase_02 AC 49 ms
4,376 KB
testcase_03 AC 202 ms
4,376 KB
testcase_04 AC 228 ms
4,380 KB
testcase_05 AC 51 ms
4,376 KB
testcase_06 AC 92 ms
4,376 KB
testcase_07 AC 42 ms
4,380 KB
testcase_08 AC 195 ms
4,376 KB
testcase_09 AC 203 ms
4,380 KB
testcase_10 AC 272 ms
4,376 KB
testcase_11 AC 261 ms
4,376 KB
testcase_12 AC 82 ms
4,380 KB
testcase_13 AC 81 ms
4,376 KB
testcase_14 AC 48 ms
4,376 KB
testcase_15 AC 42 ms
4,376 KB
testcase_16 AC 181 ms
4,376 KB
testcase_17 AC 116 ms
4,376 KB
testcase_18 AC 53 ms
4,376 KB
testcase_19 AC 267 ms
4,376 KB
testcase_20 AC 35 ms
4,380 KB
testcase_21 AC 163 ms
4,380 KB
testcase_22 AC 209 ms
4,376 KB
testcase_23 AC 69 ms
4,380 KB
testcase_24 AC 175 ms
4,380 KB
testcase_25 AC 266 ms
4,380 KB
testcase_26 AC 197 ms
4,380 KB
testcase_27 AC 199 ms
4,376 KB
testcase_28 AC 184 ms
4,380 KB
testcase_29 AC 187 ms
4,380 KB
testcase_30 AC 191 ms
4,376 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 1 ms
4,376 KB
testcase_39 AC 1 ms
4,376 KB
testcase_40 AC 2 ms
4,376 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PP;
//#define MOD 1000000007
#define MOD 998244353
#define INF 2305843009213693951
//#define INF 810114514
#define PI 3.141592653589
#define setdouble setprecision
#define REP(i,n) for(ll i=0;i<(n);++i)
#define OREP(i,n) for(ll i=1;i<=(n);++i)
#define RREP(i,n) for(ll i=(n)-1;i>=0;--i)
#define ALL(v) (v).begin(), (v).end()
#define GOODBYE do { cout << "-1" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug true
#define debug2 false

long long inverse(long long b,long long mod){
    /*
    Copyright (c) 2021 0214sh7
    https://github.com/0214sh7/library/
    */
    long long r=1,e=mod-2;
    while(e){
        if(e&1){
            r=(r*b)%mod;
        }
        b=(b*b)%mod;
        e >>=1;
    }
    return r;
}

int main(void){
    //cin.tie(nullptr);
    //ios::sync_with_stdio(false);

    ll N,M,P,Q;
    cin >> N >> M >> P >> Q;
    REP(i,Q){

        ll x,f;
        cin >> x >> f;

        if(x%P==0){
            if(f==0){
                cout << M << endl;
            }else{
                cout << 0 << endl;
            }
        }else{
            ll y = (f*inverse(x%P,P))%P;
            //cout << y << endl;
            ll Ans = (M+P-y)/P;
            if(y ==0)Ans--;
            cout << Ans << endl;
        }

    }

    return 0;
}
0