#include #include #include #include #include #define int long long #define rep(i, n) for(i = 0; i < n; i++) using namespace std; int a, b, c, d; int n; int x[100000], y[100000]; //y > 0, x : int int modulo(int x, int y) { if (x >= 0) return x % y; return (y - (-x) % y) % y; } int solve2() { int i; int det = abs(a * d - b * c); typedef pair P; set

dict; rep(i, n) { int det_mul_s = d * x[i] - c * y[i]; int det_mul_t = -b * x[i] + a * y[i]; int modS = modulo(det_mul_s, det); int modT = modulo(det_mul_t, det); dict.insert(P(modS, modT)); } return dict.size(); } int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int solve1(vector vs, int a, int b, int x[]) { int i; set dict; rep(i, vs.size()) { int xx = x[vs[i]]; int modG = xx % gcd(a, b); dict.insert(modG); } return dict.size(); } signed main() { int i; cin >> a >> b >> c >> d; cin >> n; rep(i, n) cin >> x[i] >> y[i]; if (a * d - b * c != 0) { cout << solve2() << endl; } else { map> mp; map>::iterator it; rep(i, n) { //(x, y)と(x', y')が同じ直線上 ⇔ a * y - b * x == a * y' - b * x' mp[a * y[i] - b * x[i]].push_back(i); } //同じ直線上にある点集合について1次元の問題を解く int ans = 0; for (it = mp.begin(); it != mp.end(); it++) { vector vs = it->second; int res; if (a != 0) { res = solve1(vs, a, c, x); } else { res = solve1(vs, b, d, y); } ans += res; } cout << ans << endl; } return 0; }