题意:已知gcd(a,c)=b;
输入a,b
求最小的c
思路:因为a和c的最大公因数是b
所以a%b=0 c%b=0
所以可以令c=2*b,3*b,4*b总会找到答案
再写一个求gcd的函数 如果gcd(a,c)==b
输出c就好了
gcd函数可以直接背
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
#define int long long
int gcd(int a, int b)
{
if (b == 0)return a;
return gcd(b, a % b);
}
signed main()
{
int t; cin >> t;
while (t--)
{
int a, b; cin >> a >> b;
//gcd(a,c)=b
//---->c%b==0
//求 C
int n = 2;
int c = n * b;
while (1)
{
if (gcd(a, c) == b)
{
cout << c << endl;
break;
}
n++;
c = n * b;
}
}
return 0;
}