結果

問題 No.321 (P,Q)-サンタと街の子供たち
ユーザー rlangevin
提出日時 2023-10-26 12:31:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 84 ms / 2,000 ms
コード長 566 bytes
コンパイル時間 234 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 76,160 KB
最終ジャッジ日時 2024-09-25 12:22:50
合計ジャッジ時間 4,488 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from math import gcd

P, Q = map(int, input().split())
g = gcd(P, Q)
if g == 0:
    ans = 0
    N = int(input())
    for _ in range(N):
        X, Y = map(int, input().split())
        if X == Y == 0:
            ans += 1
    print(ans)
    exit()

P //= g
Q //= g
ans = 0
N = int(input())
for _ in range(N):
    X, Y = map(int, input().split())
    if X % g or Y % g:
        continue
    X //= g
    Y //= g
    if P % 2 == 0 or Q % 2 == 0:
        ans += 1
        continue
    if X % 2 == Y % 2:
        ans += 1

print(ans)
0