結果

問題 No.2324 Two Countries within UEC
ユーザー stunniitastunniita
提出日時 2023-05-28 16:40:25
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 992 ms / 2,000 ms
コード長 661 bytes
コンパイル時間 324 ms
コンパイル使用メモリ 10,644 KB
実行使用メモリ 7,936 KB
最終ジャッジ日時 2023-09-09 06:19:52
合計ジャッジ時間 21,609 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 929 ms
7,840 KB
testcase_01 AC 992 ms
7,804 KB
testcase_02 AC 183 ms
7,832 KB
testcase_03 AC 713 ms
7,856 KB
testcase_04 AC 822 ms
7,872 KB
testcase_05 AC 200 ms
7,804 KB
testcase_06 AC 348 ms
7,832 KB
testcase_07 AC 160 ms
7,900 KB
testcase_08 AC 724 ms
7,872 KB
testcase_09 AC 731 ms
7,840 KB
testcase_10 AC 982 ms
7,844 KB
testcase_11 AC 953 ms
7,864 KB
testcase_12 AC 299 ms
7,904 KB
testcase_13 AC 298 ms
7,800 KB
testcase_14 AC 182 ms
7,816 KB
testcase_15 AC 161 ms
7,760 KB
testcase_16 AC 666 ms
7,836 KB
testcase_17 AC 435 ms
7,880 KB
testcase_18 AC 193 ms
7,936 KB
testcase_19 AC 969 ms
7,884 KB
testcase_20 AC 134 ms
7,816 KB
testcase_21 AC 562 ms
7,804 KB
testcase_22 AC 732 ms
7,808 KB
testcase_23 AC 241 ms
7,800 KB
testcase_24 AC 580 ms
7,816 KB
testcase_25 AC 962 ms
7,816 KB
testcase_26 AC 654 ms
7,872 KB
testcase_27 AC 708 ms
7,936 KB
testcase_28 AC 659 ms
7,760 KB
testcase_29 AC 659 ms
7,760 KB
testcase_30 AC 654 ms
7,872 KB
testcase_31 AC 15 ms
7,824 KB
testcase_32 AC 16 ms
7,800 KB
testcase_33 AC 16 ms
7,864 KB
testcase_34 AC 15 ms
7,816 KB
testcase_35 AC 16 ms
7,876 KB
testcase_36 AC 16 ms
7,856 KB
testcase_37 AC 16 ms
7,868 KB
testcase_38 AC 16 ms
7,836 KB
testcase_39 AC 16 ms
7,864 KB
testcase_40 AC 16 ms
7,864 KB
testcase_41 AC 16 ms
7,864 KB
testcase_42 AC 16 ms
7,936 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M,P,Q = map(int, input().split())

# (x * y) % P = f
# n^(P-1) mod P = 1
# given x and f, y = ?

# x * x^(P-2) mod P = 1
# x * f * x^(P-2) mod P = f

for _ in range(Q):
    x,f = map(int, input().split())
    y = (f * pow(x,P-2,P)) % P
    #print(f"{y=}")
    #assert x * y % P == f
    if y == 0: y = P
    """
    count = 0
    while True:
        #print(f"{y=}")
        if y > M:break
        count += 1
        y += P

    #print(f"{count=}")
    print(count)
    """
    #print(f"{y=}")
    if x % P == 0:
        if f == 0:
            print(M)
        else:
            print(0)
    elif y > M:
        print(0)
    else:
        print((M-y)//P +1)


0