CPP 문제풀이/백준

백준 2609번 : 최대공약수와 최소공배수

hjc_ 2020. 8. 24. 01:17

 

#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;
// 최대 공약수  
int GCD(int a, int b){
	int c;
	while (b != 0)
	{
		c = a % b;
		a = b;
		b = c;
	}
	return a;
}

//최소 공배수  
int LCM(int a, int b){
	int res = a * b / GCD(a, b);
	return res; 
}

int main(){
  int n, m;
  cin >> n >> m;
  cout <<  GCD(n,m) << "\n";
  cout <<  LCM(n,m) << "\n";

}