https://www.acmicpc.net/problem/13241
13241번: 최소공배수
정수 B에 0보다 큰 정수인 N을 곱해 정수 A를 만들 수 있다면, A는 B의 배수이다. 예: 10은 5의 배수이다 (5*2 = 10) 10은 10의 배수이다(10*1 = 10) 6은 1의 배수이다(1*6 = 6) 20은 1, 2, 4,5,10,20의 배수이다. 다
www.acmicpc.net
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
long a = Integer.parseInt(st.nextToken());
long b = Integer.parseInt(st.nextToken());
System.out.print(lcm(a, b));
}
static long gcd(long a, long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
static long lcm(long a, long b) {
return a * b / gcd(a, b);
}
}
'OJ' 카테고리의 다른 글
[BOJ] 1269 대칭 차집합 (JAVA) (0) | 2023.06.13 |
---|---|
[BOJ] 18115 카드 놓기 (JAVA) (0) | 2023.06.12 |
[BOJ] 11508 2+1 세일 (JAVA) (0) | 2023.06.10 |
[BOJ] 1773 폭죽쇼 (JAVA) (0) | 2023.06.09 |
[BOJ] 1735 분수 합 (JAVA) (0) | 2023.06.08 |