結果

問題 No.321 (P,Q)-サンタと街の子供たち
ユーザー 👑 SPD_9X2
提出日時 2025-08-05 23:45:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 134 ms / 2,000 ms
コード長 635 bytes
コンパイル時間 212 ms
コンパイル使用メモリ 82,612 KB
実行使用メモリ 77,208 KB
最終ジャッジ日時 2025-08-05 23:45:43
合計ジャッジ時間 5,933 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

"""

https://yukicoder.me/problems/no/321

場合分けかなぁ

1,3

X.X.
...X
X...
.X.X

とりあえず必要条件を入れてみる

"""

import math

P,Q = map(int,input().split())
P = abs(P)
Q = abs(Q)

GPQ = math.gcd(P,Q)
GS  = math.gcd(abs(P-Q),abs(P+Q))

N = int(input())

ans = 0

for i in range(N):

    X,Y = map(int,input().split())
    X = abs(X)
    Y = abs(Y)

    flag = False

    if P == 0 and Q == 0:
        if X == Y == 0:
            flag = True
    else:
        if X % GPQ == 0 and Y % GPQ == 0 and (X+Y) % GS == 0 and abs(X-Y) % GS == 0:
            flag = True

    if flag:
        ans += 1

print (ans)
0