結果
問題 | No.321 (P,Q)-サンタと街の子供たち |
ユーザー |
![]() |
提出日時 | 2021-01-04 03:47:07 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 119 ms / 2,000 ms |
コード長 | 950 bytes |
コンパイル時間 | 351 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 86,912 KB |
最終ジャッジ日時 | 2024-10-13 21:26:17 |
合計ジャッジ時間 | 5,750 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 41 |
ソースコード
from math import gcdimport sysinput = sys.stdin.buffer.readlinesys.setrecursionlimit(10 ** 7)P, Q = map(int, input().split())if P > Q:P, Q = Q, PN = int(input())XY = tuple(tuple(map(int, input().split())) for _ in range(N))ans = 0if P == 0 and Q == 0:for x, y in XY:if x == 0 and y == 0:ans += 1elif P == 0:for x, y in XY:if x % Q == 0 and y % Q == 0:ans += 1elif gcd(P, Q) == 1:if (P + Q) % 2 == 1:ans = Nelse:for x, y in XY:if (x + y) % 2 == 0:ans += 1else:g = gcd(P, Q)P //= gQ //= gif (P + Q) % 2 == 1:for x, y in XY:if x % g == 0 and y % g == 0:ans += 1else:for x, y in XY:if x % g == 0 and y % g == 0:x //= gy //= gif (x + y) % 2 == 0:ans += 1print(ans)