module main; // http://rsujskf.s602.xrea.com/?yukicoder_321 より // 2次元グリッド import std; void main() { // 入力 int P, Q; readln.chomp.formattedRead("%d %d", P, Q); int N = readln.chomp.to!int; alias T = Tuple!(int, "x", int, "y"); auto pts = new T[](N); foreach (ref p; pts) readln.chomp.formattedRead("%d %d", p.x, p.y); // 答えの計算と出力 if (P == 0) { if (Q == 0) { writeln(pts.count(T(0, 0))); return; } writeln(pts.count!(a => a.x % Q == 0 && a.y % Q == 0)); return; } if (Q == 0) { writeln(pts.count!(a => a.x % P == 0 && a.y % P == 0)); return; } int g = gcd(P, Q); P /= g, Q /= g; int ans = 0; foreach (p; pts) { if (p.x % g || p.y % g) continue; p.x /= g, p.y /= g; if ((P + Q) % 2 == 0 && (p.x + p.y) % 2 != 0) continue; ans++; } writeln(ans); }