View Code of Problem 59

//先求最大公约数 再求最小公倍数 
#include <stdio.h>
int main()
{
	int a,b,max,min;
	scanf("%d%d",&a,&b);
	max=f(a,b);
	min=a*b/max;
	printf("%d %d",min,max);
}

int f(int x,int y)  //求最大公约数用辗转相除法 f函数为关键>
{
	if(y==0)
		return x;
	else
		return f(y,x%y);
}

Double click to view unformatted code.


Back to problem 59