題意:是中文題。
析:a和c的最大公因數是b,也就是說,a和c除了b就沒有公因數了。再說就是互質了。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <cstring>
#include <map>
#include <cctype>
#include <cmath>
using namespace std;
typedef long long LL;
const int maxn = 1000000;
int a[maxn];
int gcd(int a, int b){ return b == 0 ? a : gcd(b, a%b); }
int main(){
int T, a, b; cin >> T;
while(T--){
scanf("%d %d", &a, &b);
a /= b;
for(int i = 2; ; ++i)
if(1 == gcd(i, a)) { printf("%d\n", b * i); break; }
}
return 0;
}