#include #include #include #include using namespace std; #define endl '\n' #define PB push_back #define ALL(a) (a).begin(),(a).end() #define SZ(a) int((a).size()) #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--) #define REP(i,n) FOR(i,0,n) #define RREP(i,n) for (int i=(n)-1;i>=0;i--) #define DEBUG(x) cout<<#x<<": "< P; typedef long long int LL; typedef unsigned long long ULL; typedef pair LP; #define int LL pair extgcd(long long a,long long b) { if(b==1){ return pair(0,1); } pair t=extgcd(b,a%b); return pair(t.second,t.first-a/b*t.second); } long long gcd(long long x, long long y){ return y==0 ? x : gcd(y, x%y); } signed main() { ios::sync_with_stdio(false); cin.tie(0); LL p,q; int n; cin >> p >> q; cin >> n; vector x(n),y(n); REP(i,n) cin >> x[i] >> y[i]; int ans = 0; if(p != 0 && q != 0){ LL g = gcd(p,q); P tmp = extgcd(p/g,q/g); p /= g; q /= g; int k = tmp.first, l = tmp.second; REP(i,n){ if(x[i]%g == 0 && y[i]%g == 0){ x[i] /= g; y[i] /= g; //DEBUG(x[i]); DEBUG(y[i]); DEBUG(k); DEBUG(l); bool f1 = false, f2 = false; REP(a,2){ REP(b,2){ //DEBUG(k*p+l*q); /*if((((q*b+k*y[i])+(l*x[i]-p*a))%2+2)%2 == 0 && (((l*y[i]-p*a)+(q*b+k*x[i]))%2+2)%2 == 0){ //DEBUG(i); f1 = true; }*/ if(((k*x[i]-q*a+p*b+l*y[i])%2+2)%2 == 0 && ((p*a+l*x[i]+k*y[i]-q*b)%2+2)%2 == 0){ f1 = true; } } } /*REP(a,2){ REP(b,2){ if((((l*y[i]-p*a)+(q*b+k*x[i]))%2+2)%2 == 0){ //DEBUG(i); f2 = true; } } }*/ if(f1){ //DEBUG(i); ans++; } } } }else if(p == 0 && q == 0){ REP(i,n){ if(x[i] == 0 && y[i] == 0){ ans++; } } }else{ int num = p^q; REP(i,n){ if(x[i]%num == 0 && y[i]%num == 0){ ans++; } } } cout << ans << endl; return 0; }