#include #define fst(t) std::get<0>(t) #define snd(t) std::get<1>(t) #define thd(t) std::get<2>(t) #define unless(p) if(!(p)) #define until(p) while(!(p)) using ll = std::int64_t; ll P, Q, N; template std::tuple extgcd(T a, T b){ T s1 = 1, t1 = 0, s2 = 0, t2 = 1; while(b != 0){ std::tie(s1, t1, s2, t2) = std::make_tuple(s2, t2, s1 - (a / b) * s2, t1 - (a / b) * t2); std::tie(a, b) = std::make_tuple(b, a % b); } return std::make_tuple(s1, t1, a); } bool f(ll p, ll q, ll x, ll y){ if(p == 0 && q == 0){ return x == 0 && y == 0; } ll s, t, g; std::tie(s, t, g) = extgcd(p, q); if(x % g != 0 || y % g != 0){ return false; } ll s1 = (x / g) * s, t1 = (x / g) * t, s2 = (y / g) * t, t2 = (y / g) * s; if((p / g) % 2 != (q / g) % 2){ return true; } return !((s1 + s2) & 1) && !((t1 + t2) & 1); } int main(){ std::cin.tie(nullptr); std::ios::sync_with_stdio(false); std::cin >> P >> Q >> N; int cnt = 0; for(int i=0;i> X >> Y; if(f(P, Q, X, Y)){ cnt += 1; } } std::cout << cnt << std::endl; }