// yukicoder: No.321 (P,Q)-サンタと街の子供たち // 2019.7.28 bal4u #include #if 1 #define gc() getchar_unlocked() #else #define gc() getchar() #endif int in() // 整数の入力(負数対応) { int n = 0, c = gc(); if (c == '-') { c = gc(); do n = 10*n + (c & 0xf), c = gc(); while (c >= '0'); return -n; } do n = 10*n + (c & 0xf), c = gc(); while (c >= '0'); return n; } int gcd(int a, int b) { int r; while (b != 0) r = a % b, a = b, b = r; return a; } int main() { int P, Q, N, x, y, g, ans; ans = 0; P = in(), Q = in(), N = in(); if (P == 0 && Q == 0) while (N--) x = in(), y = in(), ans += ((x | y) == 0); else if (P == 0) { if (Q == 1) ans = N; else while (N--) x = in(), y = in(), ans += (x % Q == 0) && (y % Q == 0); } else if (Q == 0) { if (P == 1) ans = N; else while (N--) x = in(), y = in(), ans += (x % P == 0) && (y % P == 0); } else { g = gcd(P, Q), P /= g, Q /= g; if ((P & 1) && (Q & 1)) while (N--) { x = in(), y = in(), ans += (x % g == 0 && y % g == 0 && ((x/g+y/g) & 1) == 0); } else if (g == 1) ans = N; else while (N--) { x = in(), y = in(), ans += (x % g == 0 && y % g == 0); } } printf("%d\n", ans); return 0; }