51Nod - 1247 可能的路径
第1行:一个数T,表示输入的测试数量(1 <= T <= 5000) 第2 - T + 1行:每行4个数,a, b, x, y,中间用空格分隔(1 <= a, b, x, y <= 10^18)
输出共T行,每行对应1个结果,如果可以,输出"Yes",否则输出"No"。
2 1 1 2 3 2 1 2 3
Yes Yes
题解:
【x, y】 可以达到的点都是与其最小公约数的倍数的点。
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
const int MAXN = 1000005;
int n, num[MAXN];
long long gcd(long long a, long long b){
if(a == 0){
return b;
}
return gcd(b%a, a);
}
int main(){
int test_num;
long long a, b, x, y, ans_1, ans_2;
while( cin >> test_num ){
for(int i=0; i<test_num; ++i){
cin >> a >> b >> x >> y;
if(a > b){
swap(a, b);
}
if(x > y){
swap(x, y);
}
ans_1 = gcd(a, b);
ans_2 = gcd(x, y);
if(ans_1 == ans_2){
cout << "Yes" << endl;
}else{
cout << "No" << endl;
}
}
}
return 0;
}
原文:http://www.cnblogs.com/zhang-yd/p/6798803.html