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

#include<stdio.h>
int f(int m, int n) {
     while (n != 0) {
         int r = m % n;
         m = n;
         n = r;
     }
     return m;
}

int main(void){
	int i,j,m,n,p;
	scanf("%d",&i);
	while(i--){
		scanf("%d%d",&m,&n);
		j=m/n;
		for(p=2;p!=1;p++){
			if(f(j,p)==1){
			    printf("%d\n",p*n); 
			    p=1;
		    }
			if(p==1){
				break;
			}					
		} 
		p=2;	    			
	}
}