Start: Mar, 06, 2018 09:46:00
计算机161 算法分析与设计 第一次实验课作业(吴银杰、张凯庆)
End: Mar, 10, 2018 10:00:00
Time elapsed:
Time remaining:

Problem_ID: D
Result: Accepted
Time: 8ms
Memory: 1092kB
Author: 2016210401015
In contest: 1141

#include<stdio.h>  
int gcd(int a,int b)  
{return b==0? a:gcd(b,a%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;  
}