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()