C/C++训练1---最大公约数与最小公倍数
Time Limit: 1000MS
Memory Limit: 65536KB
Problem Description
输入两个整数,求它们的最大公约数与最小公倍数。
Input
输入两个整数,两个整数之间用空格分开。
Output
第一行输出最大公约数;
第二行输出最小公倍数。
第二行输出最小公倍数。
Example Input
64 48
Example Output
16 192
Hint
Author
参考代码
#include <stdio.h>
int main()
{
int a,b,temp,temp1,temp2;
int i=1,i2=1;
scanf("%d%d",&a,&b);
if(a > b)
{
temp = a;
a = b;
b = temp;
}
temp1 = a;
temp2 = b;
while(b % temp1)
{
temp1 = a / i;
i++;
}
while(temp2 % a)
{
temp2 = b * i2;
i2++;
}
printf("%d\n%d",temp1,temp2);
return 0;
}