結果

問題 No.2324 Two Countries within UEC
ユーザー kyawa
提出日時 2023-05-28 13:54:04
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 887 bytes
コンパイル時間 2,038 ms
コンパイル使用メモリ 192,912 KB
最終ジャッジ日時 2025-02-13 10:27:27
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 16 WA * 25
権限があれば一括ダウンロードができます

ソースコード

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