#include using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(false); cin.tie(0); int P, Q, N, g, ans = 0; cin >> P >> Q >> N; g = __gcd(P, Q); bool flag = false; if(g >= 2 && g % 2 == 0){ flag = (P % g % 2 == Q % g % 2); } for(int i = 0; i < N; i++){ int x, y; cin >> x >> y; if(g == 0){ ans += (x == 0 && y == 0); continue; } if(x % g == 0 && y % g == 0){ if(flag){ x /= g, y /= g; ans += (x + y) % 2 == 0; }else{ ans++; } } } cout << ans << '\n'; }