from math import gcd import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 7) P, Q = map(int, input().split()) if P > Q: P, Q = Q, P N = int(input()) XY = tuple(tuple(map(int, input().split())) for _ in range(N)) ans = 0 if P == 0 and Q == 0: for x, y in XY: if x == 0 and y == 0: ans += 1 elif P == 0: for x, y in XY: if x % Q == 0 and y % Q == 0: ans += 1 elif gcd(P, Q) == 1: if (P + Q) % 2 == 1: ans = N else: for x, y in XY: if (x + y) % 2 == 0: ans += 1 else: g = gcd(P, Q) P //= g Q //= g if (P + Q) % 2 == 1: for x, y in XY: if x % g == 0 and y % g == 0: ans += 1 else: for x, y in XY: if x % g == 0 and y % g == 0: x //= g y //= g if (x + y) % 2 == 0: ans += 1 print(ans)