結果

問題 No.2324 Two Countries within UEC
ユーザー yu7400ki
提出日時 2023-05-28 14:32:06
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 425 bytes
コンパイル時間 636 ms
コンパイル使用メモリ 12,416 KB
実行使用メモリ 17,280 KB
最終ジャッジ日時 2024-12-27 01:56:01
合計ジャッジ時間 44,296 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 1
other AC * 13 WA * 22 TLE * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

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

def mod_div(a, b, p):
    return (a * pow(b, p - 2, p)) % p

ans = []
for _ in range(Q):
    x, f = map(int, input().split())
    y = mod_div(f, x, P)
    if y == 0:
        y = P
    ok = 0
    ng = M
    while ng - ok > 1:
        mid = (ok + ng) // 2
        if P * mid + y <= M:
            ok = mid
        else:
            ng = mid
    ans.append(ok + 1)

print(*ans, sep="\n")
0