原题地址
第一个想法是:枚举法暴力求解 我原以为会超时。。。没想到A了。。
这题太坑爹了
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
int gcd(int x, int y)
{
if (!x || !y) return x > y? x:y;
for (int t; t = x %y; x =y ,y =t);
return y ;
}
using namespace std;
int main()
{
int cases , a, b, i;
cin>>cases;
while (cases--)
{
cin>>a>>b;
for (i=b+1; i<=1000000; i++)
{
if (gcd(a , i) == b) break;
}
cout<<i<<endl;
}
return 0;
}