티스토리 뷰
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
class Main {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int count = Integer.parseInt(in.readLine());
String[] cases = new String[count];
for(int i=0; i<count; ++i) {
cases[i] = in.readLine();
}
for(int i=0; i<count; ++i) {
String sentence = cases[i];
String[] inputString = sentence.split(" ");
int[] input = new int[2];
for(int j=0; j<2; ++j) {
input[j] = Integer.parseInt(inputString[j]);
}
int a = input[0];
int b = input[1];
int gcd = gcd(a, b);
System.out.println(a * b / gcd);
}
}
static int gcd(int a, int b) {
if(b == 0)
return a;
return gcd(b, a % b);
}
}
A*B = L*G
최대공약수 구하는 코드 정도는 재귀함수로 구현할 줄 알아야 한다...
'Algorithm > Baekjoon Online Judge' 카테고리의 다른 글
11005번 '진법 변환 2' (0) | 2018.07.31 |
---|---|
9613번 'GCD 합' (0) | 2018.07.31 |
2609번 '최대공약수와 최소공배수' (0) | 2018.07.31 |
1912번 '연속합' (0) | 2018.07.30 |
11722번 '가장 긴 감소하는 부분 수열' (0) | 2018.07.29 |
댓글