/* No.321 (P,Q)-サンタと街の子供たち */ #include #include using namespace std; typedef long long int Int; Int gcd(Int m, Int n){ if((m == 0) || (n == 0)) return 0; while(m != n){ if(m > n) m -= n; else n -= m; } return m; } int main(){ // 読み込み Int P, Q, N; cin >> P >> Q >> N; vector X, Y; for(Int i = 0; i < N; ++i){ Int x, y; cin >> x >> y; X.push_back(x); Y.push_back(y); } // 計算 if((P == 0) && (Q == 0)){ cout << "0\n"; return 0; } if((P == 0) && (Q != 0)) P = Q; if((P != 0) && (Q == 0)) Q = P; Int R = gcd(P, Q); Int sum = 0; for(Int i = 0; i < N; ++i){ if((X[i] % R == 0) && (Y[i] % R == 0)){ Int x = abs(X[i] / R), y = abs(Y[i] / R); if(x == y){ ++sum; }else{ if((P % 2 == 0) && (Q % 2 == 1)) ++sum; if((P % 2 == 1) && (Q % 2 == 0)) ++sum; } } } cout << sum << "\n"; }