且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

hdu 2504 又见gcd

更新时间:2022-08-13 08:49:24

http://acm.hdu.edu.cn/showproblem.php?pid=2504
hint: 暴力

#include <iostream>

using namespace std;
int gcd(int m, int n)
{
    if(n==0)
    return m;
    return gcd(n, m%n);
}
int main()
{
    int a,b,t;
    cin>>t;
    while(t--)
    {
        cin>>a>>b;
        for(int i=2*b; i<=a; i++)
        {
            if(gcd(i,a)==b)
            {
                cout<<i<<endl;
                break;
            }
        }
    }
    return 0;
}