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

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