[Do It! 코딩테스트 자바편(김종관)] 문제 042(백준 1934번)
난이도
초보인 내가 봐도 너무 쉬운 문제였다.
문제
풀이
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
for (int i = 0; i < t; i++) {
StringTokenizer st = new StringTokenizer(br.readLine());
int a = Integer.parseInt(st.nextToken());
int b = Integer.parseInt(st.nextToken());
int big, small;
if (a >= b) {
big = a;
small = b;
} else {
big = b;
small = a;
}
System.out.println(lcm(big, small));
}
}
static int gcd(int big, int small) {
if (big % small == 0) {
return small;
}
return gcd(small, big % small);
}
static int lcm(int big, int small) {
int gcd = gcd(big, small);
return gcd * (big / gcd) * (small / gcd);
}
}