結果

問題 No.321 (P,Q)-サンタと街の子供たち
ユーザー matsu7874
提出日時 2015-12-14 12:51:56
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
RE  
実行時間 -
コード長 769 bytes
コンパイル時間 273 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-09-15 12:28:51
合計ジャッジ時間 9,292 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 WA * 1
other AC * 8 WA * 27 RE * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

def gcd(a, b):
    # 最大公約数
    while b > 0:
        a, b = b, a % b
    return a

def is_reachable(p,q,x,y):
    gap = gcd(p,q)
    if p%2 == q%2:
        if gap == 1:
            return x%2 == 0 and y%2==0
        elif gap == p:
            return x%p == 0 and y%p==0
        else:
            return (x%p==0 and (y+gap)%p) or ((x+gap)%p==0 and y%p)
    else:
        if gap == 1:
            return True
        elif gap == p:
            return x%p == 0 and y%p==0
        else:
            return (x%p==0 and (y+gap)%p) or ((x+gap)%p==0 and y%p)
        



P, Q = map(int, input().split())
if P > Q:
    P, Q = Q, P
N = int(input())
cnt = 0
for i in range(N):
    x,y = map(int, input().split())
    if is_reachable(P,Q,x,y):
        cnt += 1
print(cnt)
0