又见GCD
Time Limit: 1000/1000 MS ( Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 9984 Accepted Submission(s): 4157Problem Description 有三个正整数a,b,c(0
Input 第一行输入一个n,表示有n组测试数据,接下来的n行,每行输入两个正整数a,b。
Output 输出对应的c,每组测试数据占一行。
Sample Input
2 6 2 12 4
Sample Output
4 8
Source
#includeint gcd(int a, int b){ return b ? gcd(b, a % b) : a; } int main() { int n, a, b, c; scanf("%d", &n); while(n--){ scanf("%d%d", &a, &b); for(c = b << 1; ; c += b){ if(gcd(a, c) == b) break; } printf("%d\n", c); } return 0; }