Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
yukicoder No.321 (P,Q)-サンタと街の子供たち
#include <bits/stdc++.h>
#define GET_MACRO(a, b, c, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define rep2(i, a) rep3 (i, 0, a)
#define rep3(i, a, b) for (int i = (a); i < (b); i++)
#define repr(...) GET_MACRO(__VA_ARGS__, repr3, repr2)(__VA_ARGS__)
#define repr2(i, a) repr3 (i, 0, a)
#define repr3(i, a, b) for (int i = (b) - 1; i >= (a); i--)
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); }
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
using namespace std;
typedef long long ll;
int main() {
ll P, Q;
int N;
cin >> P >> Q >> N;
int ans = 0;
ll g = __gcd(P, Q);
if (g != 0) {
P /= g;
Q /= g;
}
rep (i_, N) {
ll x, y;
cin >> x >> y;
if (P == 0 && Q == 0) {
ans += x == 0 && y == 0;
continue;
}
if (x % g == 0 && y % g == 0) {
x /= g; y /= g;
if (P % 2 == 1 && Q % 2 == 1) {
if ((x + y) % 2 == 0) {
ans++;
}
} else {
ans++;
}
}
}
cout << ans << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment