結果

問題 No.321 (P,Q)-サンタと街の子供たち
ユーザー tktk_snsn
提出日時 2021-01-04 03:43:55
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 942 bytes
コンパイル時間 273 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 87,040 KB
最終ジャッジ日時 2024-10-13 21:22:54
合計ジャッジ時間 6,294 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 39 RE * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

P, Q = map(int, input().split())
if P > Q:
    P, Q = Q, P
N = int(input())
XY = tuple(tuple(map(int, input().split())) for _ in range(N))
ans = 0

if P == Q == 0:
    for x, y in XY:
        if x == 0 and y == 0:
            ans += 1
if P == 0:
    for x, y in XY:
        if x % Q == 0 and y % Q == 0:
            ans += 1
elif gcd(P, Q) == 1:
    if (P + Q) % 2 == 1:
        ans = N
    else:
        for x, y in XY:
            if (x + y) % 2 == 0:
                ans += 1
else:
    g = gcd(P, Q)
    P //= g
    Q //= g
    if (P + Q) % 2 == 1:
        for x, y in XY:
            if x % g == 0 and y % g == 0:
                ans += 1
    else:
        for x, y in XY:
            if x % g == 0 and y % g == 0:
                x //= g
                y //= g
                if (x + y) % 2 == 0:
                    ans += 1

print(ans)
0