저번 문제를 풀어서 쉽게 풀고 넘어갔다!
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for (int i = 0; i < n; i++) {
int a = sc.nextInt();
int b = sc.nextInt();
int res = gcd(a, b);
System.out.println(a*b/res);
}
}
public static int gcd(int x, int y){
while(y!=0){
int tmp = x%y;
x = y;
y = tmp;
}
return x;
}
}
야호
'백준온라인' 카테고리의 다른 글
(JAVA)백준온라인 1676번 - 팩토리얼 0의 개수 (0) | 2023.08.11 |
---|---|
(JAVA)백준온라인 6588번 - 골드바흐의 추측 (0) | 2023.08.10 |
(JAVA)백준 온라인 2609번 - 최대공약수와 최소공배수 (0) | 2023.08.07 |
(JAVA)백준 온라인 11656번 - 접미사 배열 (0) | 2023.08.04 |
(JAVA)백준 온라인 10824번 - 네 수 (0) | 2023.07.31 |