結果

問題 No.2324 Two Countries within UEC
ユーザー kyawakyawa
提出日時 2023-05-28 13:54:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 887 bytes
コンパイル時間 2,178 ms
コンパイル使用メモリ 198,592 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-27 08:38:10
合計ジャッジ時間 9,053 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 246 ms
4,376 KB
testcase_02 AC 45 ms
4,376 KB
testcase_03 AC 181 ms
4,376 KB
testcase_04 WA -
testcase_05 AC 46 ms
4,380 KB
testcase_06 WA -
testcase_07 AC 38 ms
4,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 246 ms
4,380 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 73 ms
4,380 KB
testcase_14 AC 44 ms
4,376 KB
testcase_15 WA -
testcase_16 AC 163 ms
4,380 KB
testcase_17 AC 104 ms
4,380 KB
testcase_18 WA -
testcase_19 AC 240 ms
4,376 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 243 ms
4,380 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 WA -
testcase_36 AC 1 ms
4,380 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 1 ms
4,380 KB
testcase_41 WA -
testcase_42 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

/* author: kyawa */
#include<bits/stdc++.h>
using namespace std;

/*
 考察
 count(x * y % P) == f
 Pが素数なので周期はP
 
 */

int64_t mod(int64_t a, int64_t m) {
    int64_t res = a % m;
    if (res < 0) res += m;
    return res;
}

int64_t extGCD(int64_t a, int64_t b, int64_t &p, int64_t &q) {
    if (b == 0) { p = 1; q = 0; return a; }
    int64_t d = extGCD(b, a%b, q, p);
    q -= a/b * p;
    return d;
}

int64_t modinv(int64_t a, int64_t m) {
    int64_t x, y;
    extGCD(a, m, x, y);
    return mod(x, m);
}

int main(){
    int64_t N, M, P, Q; cin >> N >> M >> P >> Q;
    while(Q--){
        int64_t res = 0;
        int64_t x, f; cin >> x >> f;
        int64_t y = modinv(x, P) * f % P;
        if(M % P >= y) res++;
        //count(k >= 0, y + P * k < M)
        res += max(int64_t(0), M - y) / P;
        if(f == 0) res--;
        cout << res << '\n';
    }
}
0