题目链接 : 屠龙宝刀,点击就送
题意 : (a,b) 给出 4种变化 ,是否能变成 (x,y)?
题解 : 整体思路 :1. 因为存在逆运算 , 可证路径可逆 , 如果能让2个点到达同一个点(m,n),则输出YES
2. (a,b) 可以变成(a-n*b,b)( 这里n为合理正整数 )
也就是变成(a%b,b)
3. 由(a%b,b)可以联想到 (b,a%b),如果成立 就可以利用 gcd 求的(m,n)最终变成 ( 0,gcd( a,b) )
所以只要推导一下是否 (a,b) 可以变成 (b,a)即可
4. 所以结论就是只要判断 2 个坐标点的 gcd 是否相等即可
代码:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
#define M 100005
#define ll long long
#define PI atan(1.0)*4
#define mst(x,v) memset(x,v,sizeof(x))
#define inf 1e9
#define rush() int T;scanf("%d",&T);while(T--)
#define debug puts("debug")
typedef pair<int,int> P;
ll gcd(ll a,ll b) {
return b?gcd(b,a%b):a;
}
int main() {
rush() {
ll a,b,x,y;
scanf("%lld %lld %lld %lld",&a,&b,&x,&y);
if(gcd(a,b) == gcd(x,y))
puts("Yes");
else
puts("No");
}
}
/*
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
*/