109. 兩數最小公倍數

 avatar
user_6817964
c_cpp
2 years ago
457 B
1
Indexable
Never
int lcm(int a, int b);

int lcm(int a, int b) {
	int max = 0;
	if (a >= b) {
		for (int i = b; i >= 1; i--) {
			if (a % i == 0 && b % i == 0) {
				max = i;
				break;
			}
		}
	}
	else {
		for (int i = a; i >= 1; i--) {
			if (a % i == 0 && b % i == 0) {
				max = i;
				break;
			}
		}
	}

	return a * b / max;
}

int main() {
	int m, n;
	scanf("%d %d", &m, &n);
	int result = lcm(m, n);
	printf("%d", result);
	return 0;
}