1 条题解
-
0
#include <bits/stdc++.h> using namespace std; long long T, A, B, X, Y; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } long long exGcd(long long a, long long b, long long &x, long long &y) { if (b == 0) { x = 1, y = 0; return a; } long long xx, yy; long long gcd = exGcd(b, a % b, xx, yy); x = yy; y = xx - (a / b) * yy; return gcd; } char check(long long x, long long y, long long a, long long b, long long xx, long long yy, long long aa, long long bb) { if ((x + xx) % 2 == 0 && (y + yy) % 2 == 0) return 'Y'; x += a; y -= b; if ((x + xx) % 2 == 0 && (y + yy) % 2 == 0) return 'Y'; xx += aa; yy -= bb; if ((x + xx) % 2 == 0 && (y + yy) % 2 == 0) return 'Y'; x -= a; y += b; if ((x + xx) % 2 == 0 && (y + yy) % 2 == 0) return 'Y'; return 'N'; } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> T; while (T--) { cin >> A >> B >> X >> Y; /* c1 * [ a, b ] + c2 * [ a, -b ] + c3 * [ b, a ] + c4 * [ b, -a ] = [ x , y ]; a * (c1 + c2) + b * (c3 + c4) = x; b * (c1 - c2) + a * (c3 - c4) = y; */ long long gcdAB = gcd(A, B); if (X % gcdAB != 0 || Y % gcdAB != 0) { cout << "N\n"; continue; } long long x, y, xx, yy; // a * (c1 + c2) + b * (c3 + c4) = x; exGcd(A, B, x, y); x = x * X / gcdAB; y = y * X / gcdAB; // b * (c1 - c2) + a * (c3 - c4) = y; exGcd(B, A, xx, yy); xx = xx * Y / gcdAB; yy = yy * Y / gcdAB; cout << check(x, y, B / gcdAB, A / gcdAB, xx, yy, A / gcdAB, B / gcdAB) << "\n"; } return 0; }
- 1
信息
- ID
- 1267
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 9
- 标签
- 递交数
- 14
- 已通过
- 4
- 上传者