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

#include<stdio.h>

int gcd(int a,int b){
	return b==0? a:gcd(b,a%b); 
}

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