问题链接:https://vjudge.net/problem/HDU-2504
Point:因为gcd(a,c)=b,所以从c=2b开始试探,找出满足gcd(a,c)=b的最小的c。
相关链接:https://blog.csdn.net/tigerisland45/article/details/51920090
AC代码:
#include <iostream>
using namespace std;
int gcd(int a, int b)
{
if (!b)
{
return a;
}
else
{
return gcd(b, a%b);
}
}
int main()
{
int n, a, b,c;
cin >> n;
while (n--)
{
cin >> a >> b;
c = 2 * b;
while (gcd(a, c) != b)
{
c += b;
}
cout << c << endl;
}
}