http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1247
问能否从(a, b)走到(x, y)
也就是能否从终点走到起点。
然后发现依次经过(a, a - b) --- (a - b, b) --- (a, a + b)就可以调换a和b的位置。
然后这就是更相减损术
所以如果gcd相同,就可以每一步走过来了
#include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <algorithm> #include <assert.h> #define IOS ios::sync_with_stdio(false) using namespace std; #define inf (0x3f3f3f3f) typedef long long int LL; #include <iostream> #include <sstream> #include <vector> #include <set> #include <map> #include <queue> #include <string> #include <bitset> void work() { LL a, b, x, y; cin >> a >> b >> x >> y; if (__gcd(a, b) == __gcd(x, y)) { cout << "Yes" << endl; } else cout << "No" << endl; } int main() { #ifdef local freopen("data.txt", "r", stdin); // freopen("data.txt", "w", stdout); #endif int t; cin >> t; while (t--) work(); return 0; }
时间: 2024-10-07 05:02:10