#include using namespace std; #define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define rep(i,n) repl(i,0,n) #define mp(a,b) make_pair((a),(b)) #define pb(a) push_back((a)) #define all(x) (x).begin(),(x).end() #define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x)) #define fi first #define se second #define dbg(x) cout<<#x" = "<<((x))< ostream& operator<<(ostream& o, const pair &p){o<<"("< ostream& operator<<(ostream& o, const vector &v){o<<"[";for(T t:v){o<>p>>q>>n; vector x(n), y(n); rep(i,n) cin>>x[i]>>y[i]; int ans=0; if(p==0 && q==0){ rep(i,n) if(x[i]==0 && y[i]==0) ans++; } else if(p==0 || q==0){ p = q = max(p,q); rep(i,n) if(x[i]%q==0 && y[i]%q==0) ans++; } else{ int g = __gcd(p,q); p /= g; q /= g; rep(i,n){ if(x[i]%g!=0 || y[i]%g!=0) continue; if(p%2==0 || q%2==0) ans++; else { x[i] /= g; if(x[i]<0) x[i] *= -1; y[i] /= g; if(y[i]<0) y[i] *= -1; if(x[i]%2 == y[i]%2) ans++; } } } cout << ans << endl; return 0; }