你说为啥每个题的坑我都会踩呢
惯性的以为c=2*b就行了
其实不是
比如144和4
如果c等于8
那么最大公约数不是4
而是8
这就说明
要得到最小的满足题意的c就得进行判断吧
用gcd吧
#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b)
{
return b?gcd(b,a%b):a;
}
int main()
{
int t,a,b;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&a,&b);
int c=2*b;
while(gcd(a,c)!=b)
{
c+=b;
}
printf("%d\n",c);
}
return 0;
}