結果

問題 No.2324 Two Countries within UEC
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-06-03 23:54:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 926 bytes
コンパイル時間 922 ms
コンパイル使用メモリ 106,664 KB
実行使用メモリ 4,564 KB
最終ジャッジ日時 2023-08-28 08:04:57
合計ジャッジ時間 8,390 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 265 ms
4,376 KB
testcase_01 AC 280 ms
4,376 KB
testcase_02 AC 51 ms
4,376 KB
testcase_03 AC 207 ms
4,376 KB
testcase_04 AC 235 ms
4,376 KB
testcase_05 AC 54 ms
4,380 KB
testcase_06 AC 95 ms
4,380 KB
testcase_07 AC 44 ms
4,376 KB
testcase_08 AC 203 ms
4,380 KB
testcase_09 AC 203 ms
4,376 KB
testcase_10 AC 278 ms
4,376 KB
testcase_11 AC 266 ms
4,376 KB
testcase_12 AC 83 ms
4,376 KB
testcase_13 AC 80 ms
4,376 KB
testcase_14 AC 49 ms
4,380 KB
testcase_15 AC 44 ms
4,376 KB
testcase_16 AC 186 ms
4,376 KB
testcase_17 AC 120 ms
4,380 KB
testcase_18 AC 55 ms
4,376 KB
testcase_19 AC 280 ms
4,380 KB
testcase_20 AC 37 ms
4,376 KB
testcase_21 WA -
testcase_22 AC 224 ms
4,376 KB
testcase_23 AC 70 ms
4,376 KB
testcase_24 WA -
testcase_25 AC 280 ms
4,380 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 1 ms
4,380 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 1 ms
4,380 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 WA -
権限があれば一括ダウンロードができます

ソースコード

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 == 0){
            cout << (f == 0 ? M : 0) << endl;
        }
        else if (gcd(x, P) != 1) cout << 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