View Code of Problem 59

#include<iostream>
#include<cstring>
#include<string>
using namespace std;
int main()
{
	int a, b;
	int temp;
	int c, d;
	cin >> a >> b;
	if (a > b) {
		temp = a;
		a = b;
		b = temp;
	}
	for (int i = 1; i <= a; i++) {
		if (a%i == 0 && b%i == 0) {
			d = i;
		}
	}
	for (int j = b; j > 0; j++) {
		if (j%a == 0 && j%b == 0) {
			c = j;
			break;
		}
	}
	cout << c << " " << d;
	return 0;
}

Double click to view unformatted code.


Back to problem 59