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

백준 1934

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

public class Main1934 {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int T = Integer.parseInt(br.readLine()); //테스트 케이스
		int[] LCD = new int[T];
		
		for(int i=0; i<T; i++){
			String str = br.readLine();
			StringTokenizer st = new StringTokenizer(str);
			int a = Integer.parseInt(st.nextToken());
			int b = Integer.parseInt(st.nextToken());
			int g = GCD(a,b);	//최대공약수
			LCD[i] = g* (a/g) * (b/g);
		}
		
		for(int i=0; i<T; i++){
			System.out.println(LCD[i]);
		}
		
	}
	
	//유클리드 호제법 사용 (재귀)
	public static int GCD(int a, int b){
		if(b == 0){
			return a;
		}else{
			return GCD(b, a%b);
		}
	}

}

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

백준 1978  (0) 2021.08.12
백준 2609  (0) 2021.08.10
백준 17299  (0) 2021.08.09
백준 17298  (0) 2021.08.09
백준 10799  (0) 2021.08.09