Problem Description
有三个正整数a,b,c(0<a,b,c<10^6),其中c不等于b。若a和c的最大公约数为b,现已知a和b,求满足条件的最小的c。
Input
第一行输入一个n,表示有n组测试数据,接下来的n行,每行输入两个正整数a,b。
Output
输出对应的c,每组测试数据占一行。
Sample Input
2
6 2
12 4
Sample Output
4
8
Problem Description
有三个正整数a,b,c(0<a,b,c<10^6),其中c不等于b。若a和c的最大公约数为b,现已知a和b,求满足条件的最小的c。
Input
第一行输入一个n,表示有n组测试数据,接下来的n行,每行输入两个正整数a,b。
Output
输出对应的c,每组测试数据占一行。
Sample Input
2
6 2
12 4
Sample Output
4
8
满足条件的最小的C应该是 b*2
参考代码如下:
#include
#include
#include
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int i, n, a, b, d;
int *c;
printf("Sample Input\n");
scanf("%d", &n);
c = (int*)malloc(n*(sizeof(int)));
memset(c, 0, n);
if(n > 0)
{
i = n;
for(;i > 0;i --)
{
scanf("%d %d", &a, &b);
c[i] = b * 2;
}
printf("Sample Output\n");
i = n;
for(;i > 0;i --)
{
printf("%d\n", c[i]);
}
}
free(c);
return 0;
}