結果
問題 |
No.321 (P,Q)-サンタと街の子供たち
|
ユーザー |
![]() |
提出日時 | 2025-03-20 20:42:53 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,087 bytes |
コンパイル時間 | 260 ms |
コンパイル使用メモリ | 82,248 KB |
実行使用メモリ | 93,804 KB |
最終ジャッジ日時 | 2025-03-20 20:43:09 |
合計ジャッジ時間 | 4,362 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 20 WA * 21 |
ソースコード
import math def main(): import sys input = sys.stdin.read().split() idx = 0 P = int(input[idx]); idx += 1 Q = int(input[idx]); idx += 1 N = int(input[idx]); idx += 1 count = 0 for _ in range(N): X = int(input[idx]); idx += 1 Y = int(input[idx]); idx += 1 if P == 0 and Q == 0: if X == 0 and Y == 0: count += 1 continue if P == 0: if Q != 0 and X % Q == 0 and Y % Q == 0: count += 1 continue if Q == 0: if P != 0 and X % P == 0 and Y % P == 0: count += 1 continue # Both P and Q are non-zero g = math.gcd(P, Q) if X % g != 0 or Y % g != 0: continue x = X // g y = Y // g sum_xy = x + y diff_xy = x - y # Compute gcd of (P + Q) and |P - Q| g2 = math.gcd(P + Q, abs(P - Q)) if sum_xy % g2 == 0 and diff_xy % g2 == 0: count += 1 print(count) if __name__ == '__main__': main()