結果

問題 No.321 (P,Q)-サンタと街の子供たち
ユーザー lloyz
提出日時 2023-10-26 07:29:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 158 ms / 2,000 ms
コード長 565 bytes
コンパイル時間 445 ms
コンパイル使用メモリ 82,164 KB
実行使用メモリ 86,168 KB
最終ジャッジ日時 2024-09-25 12:16:47
合計ジャッジ時間 7,514 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd

p, q = map(int, input().split())
n = int(input())
P = [list(map(int, input().split())) for _ in range(n)]

ans = 0
if p == q == 0:
    for i in range(n):
        x, y = P[i]
        if x == y == 0:
            ans += 1
else:
    g = gcd(p, q)
    p //= g
    q //= g
    if (p + q) % 2 == 0:
        bi = True
    else:
        bi = False
    for i in range(n):
        x, y = P[i]
        if x % g != 0 or y % g != 0:
            continue
        x //= g
        y //= g
        if not bi or (x + y) % 2 == 0:
            ans += 1
print(ans)
0