方法:辗转相除
辗转相除法
有两整数a和b:
① a%b得余数c
② 若c=0,则b即为两数的最大公约数
③ 若c≠0,则a=b,b=c,再回去执行①
a * b除以最大公约数 等于最小公倍数
代码如下所示
int max(int *x,int *y)
{
int temp;
if(*x<*y)
{
temp=*x;
*x=*y;
*y=temp;
}
}
int division(int x,int y)
{
int temp;
max(&x,&y);
while(x%y!=0)
{
temp=x%y;
x=y;
y=temp;
}
return y;
}
int main()
{
long int x0,y0;
int a,b;
cin>>x0>>y0;
a=division(x0,y0);
b=x0*y0/a;
cout<<a<<" "<<b<<endl;
return 0;
}