結果

問題 No.321 (P,Q)-サンタと街の子供たち
ユーザー matsu7874matsu7874
提出日時 2015-12-14 12:51:56
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 769 bytes
コンパイル時間 393 ms
コンパイル使用メモリ 10,772 KB
実行使用メモリ 8,004 KB
最終ジャッジ日時 2023-10-13 16:28:48
合計ジャッジ時間 8,122 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 16 ms
7,848 KB
testcase_02 AC 16 ms
7,968 KB
testcase_03 AC 16 ms
7,800 KB
testcase_04 WA -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 AC 16 ms
7,972 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 296 ms
7,800 KB
testcase_16 RE -
testcase_17 AC 16 ms
7,812 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 297 ms
7,952 KB
testcase_21 WA -
testcase_22 RE -
testcase_23 AC 250 ms
7,856 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 330 ms
7,840 KB
testcase_30 AC 22 ms
7,860 KB
testcase_31 WA -
testcase_32 AC 171 ms
7,796 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
権限があれば一括ダウンロードができます

ソースコード

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