""" https://yukicoder.me/problems/no/321 場合分けかなぁ 1,3 """ import math P,Q = map(int,input().split()) P = abs(P) Q = abs(Q) G = math.gcd(abs(P-Q),abs(P+Q)) N = int(input()) ans = 0 for i in range(N): X,Y = map(int,input().split()) flag = False if P == 0 and Q == 0: if X == Y == 0: flag = True else: if X % G == 0 and Y % G == 0: flag = True if flag: ans += 1 print (ans)