結果

問題 No.2324 Two Countries within UEC
ユーザー Cyanmond
提出日時 2023-05-28 14:47:30
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 245 ms / 2,000 ms
コード長 714 bytes
コンパイル時間 1,780 ms
コンパイル使用メモリ 195,216 KB
最終ジャッジ日時 2025-02-13 12:04:32
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include "atcoder/modint"

using i64 = long long;
using Mint = atcoder::dynamic_modint<1>;

int main() {
    i64 N, M, P;
    int Q;
    std::cin >> N >> M >> P >> Q;
    Mint::set_mod(P);
    while (Q--) {
        i64 x, f;
        std::cin >> x >> f;
        x %= P;
        if (x == 0) {
            if (f == 0) {
                std::cout << M << std::endl;
            } else {
                std::cout << 0 << std::endl;
            }
            continue;
        }
        Mint inv = Mint(f) / Mint(x);
        i64 v = inv.val();
        if (v > M) std::cout << 0 << std::endl;
        else {
            std::cout << (M - v) / P + (f == 0 ? 0 : 1) << std::endl;
        }
    }
}
0