#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define var auto
#define mod 1000000007
#define inf 2147483647
#define nil -1
#define mp make_pair
typedef long long ll;
using namespace std;

template <typename T>
inline void output(T a, int p) {
    if(p){
        cout << fixed << setprecision(p)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}
// end of template

int gcd(int a, int b){
    if (b == 0) {
        return a;
    }
    else{
        return gcd(b, a % b);
    }
}

bool judge(int x, int y, int p, int q, int g){
    if (x % g != 0 || y % g != 0 || (x + y) % gcd(p + q, abs(p - q)) != 0) {
        return false;
    }
    return true;
}

bool judge0(int x, int y){
    if (x == 0 && y == 0) {
        return true;
    }
    return false;
}

int main() {
    cin.tie(0);
    // source code
    
    int P, Q, N;
    cin >> P >> Q >> N;
    int G = gcd(P, Q);
    
    int cnt = 0;
    
    if (P == 0 && Q == 0) {
        rep(i, N){
            int x, y;
            cin >> x >> y;
            cnt += judge0(x, y) ? 1 : 0;
        }
    }
    else{
        rep(i, N){
            int x, y;
            cin >> x >> y;
            cnt += judge(x, y, P, Q, G) ? 1 : 0;
        }
    }
    
    
    cout << cnt << endl;
    
    return 0;
}