View Code of Problem 59

#include <stdio.h>

int main() {
	int a, b;
	scanf("%d %d", &a, &b);
	int gb, gy;
	int max, min;
	max = a > b ? a : b;
	min = a < b ? a : b;
	gb = max;
	gy = min;
	while (1) {
		if (gb%a == 0 && gb%b == 0) {
			break;
		}
		else
		{
			gb += max;
		}
	}
	while (1) {
		if (a%gy == 0 && b%gy == 0) {
			break;
		}
		else
		{
			gy--;
		}
	}
	printf("%d %d", gb, gy);
}

Double click to view unformatted code.


Back to problem 59