結果

問題 No.2324 Two Countries within UEC
ユーザー InTheBloomInTheBloom
提出日時 2023-05-28 14:43:58
言語 D
(dmd 2.106.1)
結果
MLE  
実行時間 -
コード長 1,274 bytes
コンパイル時間 2,441 ms
コンパイル使用メモリ 160,296 KB
実行使用メモリ 812,496 KB
最終ジャッジ日時 2023-09-04 20:29:07
合計ジャッジ時間 10,447 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 205 ms
4,352 KB
testcase_01 AC 225 ms
4,376 KB
testcase_02 AC 39 ms
4,376 KB
testcase_03 AC 159 ms
4,380 KB
testcase_04 AC 182 ms
4,376 KB
testcase_05 AC 43 ms
4,380 KB
testcase_06 AC 75 ms
4,376 KB
testcase_07 AC 35 ms
4,380 KB
testcase_08 AC 154 ms
4,380 KB
testcase_09 AC 158 ms
4,376 KB
testcase_10 AC 223 ms
4,384 KB
testcase_11 AC 208 ms
4,376 KB
testcase_12 AC 66 ms
4,380 KB
testcase_13 AC 65 ms
4,380 KB
testcase_14 AC 41 ms
4,376 KB
testcase_15 AC 35 ms
4,380 KB
testcase_16 AC 149 ms
4,376 KB
testcase_17 AC 97 ms
4,380 KB
testcase_18 AC 41 ms
4,380 KB
testcase_19 AC 219 ms
4,376 KB
testcase_20 AC 28 ms
4,376 KB
testcase_21 AC 110 ms
4,376 KB
testcase_22 AC 142 ms
4,376 KB
testcase_23 AC 47 ms
4,376 KB
testcase_24 AC 116 ms
4,380 KB
testcase_25 AC 213 ms
4,380 KB
testcase_26 AC 113 ms
4,376 KB
testcase_27 AC 119 ms
4,380 KB
testcase_28 AC 114 ms
4,380 KB
testcase_29 AC 113 ms
4,376 KB
testcase_30 AC 114 ms
4,380 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 1 ms
4,384 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 1 ms
4,376 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 MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

void main () {
    long N, M, P, Q;
    {
        auto buf = readln.split.to!(long[]);
        N = buf[0], M = buf[1], P = buf[2], Q = buf[3];
    }
    solve(N, M, P, Q);
}

void solve (long N, long M, long P, long Q) {
    foreach (_; 0..Q) {
        auto buf = readln.split.to!(long[]);
        long x = buf[0], f = buf[1];

        if (x % P != 0) {
        // x^{-1}が存在
            long inv_x = modinv(x, P);
            long modular = (f * inv_x) % P;
            // y == modular(MOD P)

            if (M < modular) {
                writeln(0);
            } else if (modular != 0) {
                writeln(1 + (M - modular)/P);
            } else {
                writeln((M - modular)/P);
            }
        } else {
        // x^{-1}が存在しない(任意のyについて親交度が0である)
            if (f == 0) {
                writeln(M);
            } else {
                writeln(0);
            }
        }
    }
}

long modpow (long x, long a, const long MOD) {
    if (a == 1) {
        return x;
    }
    if (a % 2 == 1) {
        return (x * modpow(x, a-1, MOD)) % MOD;
    }
    long t = modpow(x, a/2, MOD);
    return (t * t) % MOD;
}

long modinv (long x, const long MOD) {
    return modpow(x, MOD - 2, MOD);
}
0