#include using namespace std; //typedef //------------------------------------------ typedef vector VI; typedef vector VVI; typedef vector VS; typedef pair PII; typedef long long LL; //container util //------------------------------------------ #define ALL(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) #define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i) #define EXIST(s,e) ((s).find(e)!=(s).end()) #define SORT(c) sort((c).begin(),(c).end()) //repetition //------------------------------------------ #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) //constant //-------------------------------------------- const double EPS = 1e-10; const double PI = acos(-1.0); int main(){ cin.tie(0); ios_base::sync_with_stdio(false); LL P, Q; cin >> P >> Q; LL N; cin >> N; LL ans = 0; if(Q < P) swap(P, Q); if(P == 0 && Q == 0){ REP(i,N){ LL x, y; cin >> x >> y; if(x == 0 && y == 0) ++ans; } cout << ans << endl; return 0; } LL d = __gcd(P, Q); LL n = Q / d, m = P / d; n %= 2; m %= 2; LL tmp = n*Q + m*P; tmp = __gcd(tmp, 2*P); tmp = __gcd(tmp, 2*Q); REP(i,N){ LL x, y; cin >> x >> y; x = abs(x); y = abs(y); if(x % tmp == 0 && y % tmp == 0) ++ans; else if((x+P)%tmp == 0 && (y+Q) % tmp == 0) ++ans; } cout << ans << endl; return 0; }