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: yeruibin200
In contest: 1141

#include<stdio.h>
int gcd(int a,int b){
	if(a<b){
		int temp = a;
		a = b;
		b = temp;
	}
	if(a%b==0)	return b;
	
	else return gcd(b,a%b);
} 
int main(){
	int T;
	scanf("%d",&T);
	while(T--){
		int a,b;
		scanf("%d%d",&a,&b);
		for(int i=2;;++i){
			if(gcd(i*b,a)==b){
				printf("%d\n",i*b);
				break;
			}
		} 
	}
}