There are three positive integers a,b,c (0<a,b,c<10^6), where c is not equal to b. If the greatest common divisor of a and c is b, now a and b are known, find the smallest c that satisfies the condition.
Input input an n in the first line, indicating that there are n groups of test data, the next n lines, each line input two positive integers a, b.
Output outputs the corresponding c, and each set of test data occupies one line.
Sample Input
2 6 2 12 4Sample Output
4 8
code show as below:
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll gcd(ll a,ll b){ while(b^=a^=b^=a%=b); return a; } int main(){ int t; cin>>t; while(t--){ ll a,b; cin>>a>>b; for(ll i=1;i<=a*b;i++){ if(gcd(a,i)==b&&i!=b) { cout<<i<<endl; break; } } } return 0; }