辗转相除法。。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\n",c);
    }
    return 0;
} 
View Code

 

posted @ 2013-08-13 22:00  执着追求的IT小小鸟  阅读(135)  评论(0编辑  收藏  举报