辗转相除法。。HDU2504

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

#include<stdio.h>
int gcd(int a,int b)
{
    int r=a%b;
    while(r)
    {
       a=b;
       b=r;
       r=a%b;
    }
    return b;
}
int main()
{
    int t,a,b,c;
    scanf("%d",&t);
    while(t--)
    {
       scanf("%d%d",&a,&b);
       c=2*b;
       while(gcd(a,c)!=b)
       c+=b;
       printf("%d
",c);
    }
    return 0;
} 
View Code
原文地址:https://www.cnblogs.com/huzhenbo113/p/3256130.html