結果
問題 | No.321 (P,Q)-サンタと街の子供たち |
ユーザー |
![]() |
提出日時 | 2015-12-19 01:09:59 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 36 ms / 2,000 ms |
コード長 | 2,087 bytes |
コンパイル時間 | 1,281 ms |
コンパイル使用メモリ | 163,064 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-06 22:06:38 |
合計ジャッジ時間 | 3,198 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 41 |
ソースコード
#include <bits/stdc++.h>#include <cmath>#include <climits>#include <cstdio>using namespace std;#define endl '\n'#define PB push_back#define ALL(a) (a).begin(),(a).end()#define SZ(a) int((a).size())#define FOR(i,a,b) for(int i=(a);i<(b);++i)#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)#define REP(i,n) FOR(i,0,n)#define RREP(i,n) for (int i=(n)-1;i>=0;i--)#define DEBUG(x) cout<<#x<<": "<<x<<endl#define AALL(a,n) (a),(a)+(n)typedef pair<int,int> P;typedef long long int LL;typedef unsigned long long ULL;typedef pair<LL,LL> LP;#define int LLpair<long long, long long> extgcd(long long a,long long b){if(b==1){return pair<long long, long long>(0,1);}pair<long long, long long> t=extgcd(b,a%b);return pair<long long, long long>(t.second,t.first-a/b*t.second);}long long gcd(long long x, long long y){return y==0 ? x : gcd(y, x%y);}signed main(){ios::sync_with_stdio(false);cin.tie(0);LL p,q;int n;cin >> p >> q;cin >> n;vector<int> x(n),y(n);REP(i,n) cin >> x[i] >> y[i];int ans = 0;if(p != 0 && q != 0){LL g = gcd(p,q);P tmp = extgcd(p/g,q/g);p /= g; q /= g;int k = tmp.first, l = tmp.second;REP(i,n){if(x[i]%g == 0 && y[i]%g == 0){x[i] /= g;y[i] /= g;//DEBUG(x[i]); DEBUG(y[i]); DEBUG(k); DEBUG(l);bool f1 = false, f2 = false;REP(a,2){REP(b,2){//DEBUG(k*p+l*q);/*if((((q*b+k*y[i])+(l*x[i]-p*a))%2+2)%2 == 0 && (((l*y[i]-p*a)+(q*b+k*x[i]))%2+2)%2 == 0){//DEBUG(i);f1 = true;}*/if(((k*x[i]-q*a+p*b+l*y[i])%2+2)%2 == 0 && ((p*a+l*x[i]+k*y[i]-q*b)%2+2)%2 == 0){f1 = true;}}}/*REP(a,2){REP(b,2){if((((l*y[i]-p*a)+(q*b+k*x[i]))%2+2)%2 == 0){//DEBUG(i);f2 = true;}}}*/if(f1){//DEBUG(i);ans++;}}}}else if(p == 0 && q == 0){REP(i,n){if(x[i] == 0 && y[i] == 0){ans++;}}}else{int num = p^q;REP(i,n){if(x[i]%num == 0 && y[i]%num == 0){ans++;}}}cout << ans << endl;return 0;}