1934번: 최소공배수
https://www.acmicpc.net/problem/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));
StringBuilder sb = new StringBuilder();
// 테스트 케이스의 개수 T
int t = Integer.parseInt(br.readLine());
StringTokenizer st;
for (int i = 0; i < t; i++) {
st = new StringTokenizer(br.readLine(), " ");
int a = Integer.parseInt(st.nextToken());
int b = Integer.parseInt(st.nextToken());
int j = 1;
int x = a;
while (true) {
if ((x % a == 0) && (x % b == 0)) {
sb.append(x).append("\n");
break;
}
j++;
x = a * j;
}
}
System.out.print(sb);
br.close();
}
}
'코딩테스트 > 자바 문제풀이' 카테고리의 다른 글
[수학] 백준 4134 다음 소수 (0) | 2024.08.11 |
---|---|
[수학] 백준 2609 최대공약수와 최소공배수 (0) | 2024.08.09 |
[수학] 백준 11653 소인수분해 (0) | 2024.08.07 |
[수학] 백준 1110 더하기 사이클 (0) | 2024.08.06 |
[수학] 백준 5618 공약수 (0) | 2024.08.05 |