View Code of Problem 59

#include<stdio.h>

int main()
{
	int a, b;
	int x, y;
	scanf("%d %d", &a, &b);
	
	if(a > b)
	{
		for(int i = a; i <= a*b; i++)
			if(i % a == 0 && i % b == 0)
			{
				x = i;
				break;
			}	
		for(int i = b; i >= 1; i--)
			if(a % i == 0 && b % i == 0)
			{
				y = i;
				break;
			}
	}
	else
	{
		for(int i = b; i <= a*b; i++)
			if(i % a == 0 && i % b == 0)
			{
				x = i;
				break;
			}	
		for(int i = a; i >= 1; i--)
			if(a % i == 0 && b % i == 0)
			{
				y = i;
				break;
			}
	}
	printf("%d %d", x, y);
	return 0;
 } 

Double click to view unformatted code.


Back to problem 59