#include using namespace std; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FORR(x,arr) for(auto&& x:arr) #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 (int i = 0; i < (n); i++) #define RREP(i,n) for (int i = (n)-1; i >= 0; i--) #define ALL(x) (x).begin(), (x).end() #define BIT(n) (1LL<<(n)) #define SZ(x) ((int)(x).size()) #define fst first #define snd second #define DUMP( x ) cerr << #x << " = " << ( x ) << endl typedef long long ll; // ------------------------------------- void Main() { int P, Q; scanf("%d %d", &P, &Q); int N; scanf("%d", &N); int gcd = P == 0 && Q == 0 ? 1 : __gcd(P, Q); P /= gcd; Q /= gcd; P %= 2; Q %= 2; int ans = 0; REP(i, N) { int x, y; scanf("%d %d", &x, &y); if (P == 0 && Q == 0) ans += (x == 0 && y == 0 ? 1 : 0); else if (P == 0 || Q == 0) ans++; else { // 一般 if (x % gcd == 0 && y % gcd == 0) { // gcd(P,Q) の倍数しかいけない if (P && Q) { // 互いに素にしたP,Qが両方奇数のときはいけない場所がある if ((x + y) % 2) ans++; } else ans++; } } } _P("%d\n", ans); } int main() { cin.tie(0); ios::sync_with_stdio(false); Main(); return 0; }