#include using namespace std; namespace { typedef double real; typedef long long ll; template ostream& operator<<(ostream& os, const vector& vs) { if (vs.empty()) return os << "[]"; os << "[" << vs[0]; for (int i = 1; i < vs.size(); i++) os << " " << vs[i]; return os << "]"; } template istream& operator>>(istream& is, vector& vs) { for (auto it = vs.begin(); it != vs.end(); it++) is >> *it; return is; } ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; } ll extgcd(ll a, ll b, ll& x, ll& y) { ll g = a; x = 1LL; y = 0LL; if (b != 0LL) { g = extgcd(b, a % b, y, x); y -= (a / b) * x; } return g; } ll P, Q; int N; bool eql2(ll a, ll b) { a = abs(a); b = abs(b); return a % 2 == b % 2; } bool check(ll x, ll y) { if (P == 0 && Q == 0) return x == 0 && y == 0; if (P == Q) return x == y && (x % P == 0); ll n, m; ll g = extgcd(P, Q, n, m); ll a, b; extgcd(Q, P, a, b); ll dP = lcm(P, Q) / P; ll dQ = lcm(P, Q) / Q; for (int i = -1; i <= 1; i++) { for (int j = -1; j <= 1; j++) { if ( eql2(n + i * dP, a + j * dQ) && eql2(m + (-i) * dQ, b + (-i) * dP) ) { return true; } } } return false; } void solve() { cin >> P >> Q >> N; int ans = 0; for (int i = 0; i < N; i++) { ll x, y; cin >> x >> y; //cout << x << " " << y << " -> " << check(x, y) << endl; ans += check(x, y); } cout << ans << endl; } } int main() { solve(); return 0; }