結果

問題 No.2324 Two Countries within UEC
ユーザー hiikunZhiikunZ
提出日時 2023-05-28 13:36:44
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 226 ms / 2,000 ms
コード長 1,089 bytes
コンパイル時間 3,659 ms
コンパイル使用メモリ 214,204 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-09 06:01:29
合計ジャッジ時間 9,619 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 212 ms
4,380 KB
testcase_01 AC 225 ms
4,380 KB
testcase_02 AC 40 ms
4,380 KB
testcase_03 AC 165 ms
4,376 KB
testcase_04 AC 194 ms
4,380 KB
testcase_05 AC 43 ms
4,376 KB
testcase_06 AC 78 ms
4,376 KB
testcase_07 AC 35 ms
4,380 KB
testcase_08 AC 167 ms
4,380 KB
testcase_09 AC 172 ms
4,380 KB
testcase_10 AC 225 ms
4,376 KB
testcase_11 AC 214 ms
4,380 KB
testcase_12 AC 68 ms
4,376 KB
testcase_13 AC 67 ms
4,380 KB
testcase_14 AC 41 ms
4,376 KB
testcase_15 AC 36 ms
4,376 KB
testcase_16 AC 154 ms
4,376 KB
testcase_17 AC 95 ms
4,380 KB
testcase_18 AC 44 ms
4,376 KB
testcase_19 AC 224 ms
4,380 KB
testcase_20 AC 30 ms
4,380 KB
testcase_21 AC 136 ms
4,376 KB
testcase_22 AC 179 ms
4,376 KB
testcase_23 AC 57 ms
4,376 KB
testcase_24 AC 150 ms
4,376 KB
testcase_25 AC 226 ms
4,376 KB
testcase_26 AC 152 ms
4,376 KB
testcase_27 AC 153 ms
4,376 KB
testcase_28 AC 151 ms
4,380 KB
testcase_29 AC 147 ms
4,376 KB
testcase_30 AC 153 ms
4,380 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 1 ms
4,380 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 1 ms
4,380 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
ll modinv(ll A,ll M){
    //A*r+B*n=gcd(A,B)
    A %= M;
    if(A == 0 || __gcd(A,M) != 1){
        //cout << "Error modinv(" << A << "," << M << ")" << endl;
        return -1;
    }
    ll B = M,U = 1,V = 0;
    while(B){
        ll 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(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N,M,P,Q;
    cin >> N >> M >> P >> Q;
    for(ll q = 0;q < Q;q++){
        ll x,f;
        cin >> x >> f;
        x %= P;
        if(x == 0){
            if(f == 0) cout << M << endl;
            else cout << 0 << endl;
        }
        else{
            ll y = (f * modinv(x,P)) % P;
            ll ans = M / P;
            if(y != 0 && y <= M % P) ans++;
            cout << ans << endl;
        }
    }
}
0