#include #define GET_MACRO(a, b, c, NAME, ...) NAME #define rep(...) GET_MACRO(__VA_ARGS__, rep3, rep2)(__VA_ARGS__) #define rep2(i, a) rep3 (i, 0, a) #define rep3(i, a, b) for (int i = (a); i < (b); i++) #define repr(...) GET_MACRO(__VA_ARGS__, repr3, repr2)(__VA_ARGS__) #define repr2(i, a) repr3 (i, 0, a) #define repr3(i, a, b) for (int i = (b) - 1; i >= (a); i--) template inline bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); } template inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } using namespace std; typedef long long ll; bool check(ll x, ll y, ll x1, ll y1, ll x2, ll y2) { ll D = x1 * y2 - x2 * y1; if (D == 0) { if (y1 == 0 && x1 == 0) { return x == 0 && y == 0; } if (y1 == 0) { if (y != 0) return false; return x % x1 == 0; } if (x1 == 0) { if (x != 0) return false; return y % y1 == 0; } if (x % x1 == 0 && y % y1 == 0) { return abs(x / x1) == abs(y / y1); } else { return false; } } else { ll tx = y2 * x - x2 * y; ll ty = -y1 * x + x1 * y; return tx % D == 0 && ty % D == 0; } } int main() { ll P, Q; int N; cin >> P >> Q >> N; int ans = 0; rep (i_, N) { ll x, y; cin >> x >> y; x = abs(x); y = abs(y); bool ok = false; ok |= check(x, y, P, Q, Q, -P); ok |= check(x, y, P, Q, Q, P); ok |= check(x, y, Q, P, P, -Q); ok |= check(x, y, Q, P, P, Q); ok |= check(x, y, P, Q, P, -Q); ok |= check(x, y, P, Q, P, Q); ok |= check(x, y, Q, P, Q, -P); ok |= check(x, y, Q, P, Q, P); if (ok) ans++; } cout << ans << endl; return 0; }