시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
1 초 | 128 MB | 56311 | 33173 | 26910 | 60.172% |
두 개의 자연수를 입력받아 최대 공약수와 최소 공배수를 출력하는 프로그램을 작성하시오.
첫째 줄에는 두 개의 자연수가 주어진다. 이 둘은 10,000이하의 자연수이며 사이에 한 칸의 공백이 주어진다.
첫째 줄에는 입력으로 주어진 두 수의 최대공약수를, 둘째 줄에는 입력으로 주어진 두 수의 최소 공배수를 출력한다.
24 18
6
72
import java.io.*;
import java.util.Arrays;
public class P_2609 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int[] array = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
int a = array[0];
int b = array[1];
int gcd = 1, lcm = 0;
for (int i = 2; i <= (Math.min(a, b)); i++) {
if (a % i == 0 && b % i == 0)
gcd = i;
}
lcm = a * (b / gcd);
bw.write(gcd + "\n");
bw.write(Integer.toString(lcm));
bw.flush();
}
}