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: 6ms
Memory: 1092kB
Author: 2016210401027
In contest: 1141

#include<stdio.h>

int gcd(int m,int n)
{
    int t;
    while(n)
    {
        t=m;
        m=n;
        n=t%n;
    }
    return m;
}

int main()
{
    int n,a,b,c;
    scanf("%d",&n);
    while(n--)
    {
        scanf("%d%d",&a,&b);
		c=2*b;
		while(gcd(a,c)!=b)
			  c+=b;
		printf("%d\n",c);
		
    }
    return 0;
}