4314. Coprime
Description
In number theory, a branch of mathematics, two integers a and b are said to be coprime or relatively prime if the only positive integer that evenly divides both of them is 1. This is the same thing as their greatest common divisor being 1. In addition to gcd(a,b)=1 and (a,b)=1. Now, give you two numbers a and b, can you tell me whether a and b are coprime?
Input
The first line contains an integer T(1<=T<=10), indicating the number of test cases.
Then, for each case, there are two integers a, b (1<=a, b<=1000) in one line.
Output
One line for each case. Print “Yes”(without quotation) if a and b are coprime, otherwise print “No”(without quotation).
Sample Input
2
3 4
256 512
Sample Output
Yes
No
// source code of submission 1029317, Zhongshan University Online Judge System
#include <iostream>
using namespace std;
int main()
{
int n,a,b;
cin >> n;
while (n--)
{
int min ;
cin >> a >> b;
if(a<b)
min = a;
else
min = b;
int i = 2;
for( ;i <= min;i++)
{
if(a%i == 0&&b%i ==0)
{
cout << "No" << endl;
break;
}
}
if(i == min +1)
cout << "Yes" << endl;
}
return 0;
}