본문 바로가기
알고리즘 & 자료구조/백준

백준 2609

by 신재권 2021. 8. 10.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main2609 {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		StringTokenizer st = new StringTokenizer(str);
		
		int a = Integer.parseInt(st.nextToken());
		int b = Integer.parseInt(st.nextToken());
		
		int GCD = GCD(a, b);	//최대공약수
		
		//최대공약수를 이용해서 최소 공배수를 구할 수 있다.
		int LCD = (a/GCD)*(b/GCD)*GCD;  //최소공배수
		
		System.out.println(GCD);
		System.out.println(LCD);
		
	}
	
	//유클리드 호제법 사용 (재귀)
	public static int GCD(int a, int b){
		if(b == 0){
			return a;
		}else{
			return GCD(b, a%b);
		}
	}

}

'알고리즘 & 자료구조 > 백준' 카테고리의 다른 글

백준 1929  (0) 2021.08.12
백준 1978  (0) 2021.08.12
백준 1934  (0) 2021.08.10
백준 17299  (0) 2021.08.09
백준 17298  (0) 2021.08.09