您的位置:首页 > 其它

ACMSTEP 2.1.5 又见GCD //数论 GCD

2011-08-10 12:23 344 查看
原题地址

第一个想法是:枚举法暴力求解 我原以为会超时。。。没想到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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: