Skip to content

Commit 1bad105

Browse files
authored
대부분의 배수 (#75)
1 parent ed01135 commit 1bad105

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

pr/대부분의 배수/Main.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import java.util.*;
2+
3+
public class Main {
4+
static int[] arr = new int[5];
5+
6+
static int min = Integer.MAX_VALUE;
7+
8+
public static void main(String[] args) {
9+
10+
Scanner sc = new Scanner(System.in);
11+
12+
for (int i = 0; i < 5; i++) {
13+
arr[i] = sc.nextInt();
14+
}
15+
16+
solve();
17+
18+
}
19+
20+
public static void solve() {
21+
22+
for (int i = 0; i < 5; i++) {
23+
for (int j = i + 1; j < 5; j++) {
24+
for (int k = j + 1; k < 5; k++) {
25+
int lcm = lcm(arr[i], arr[j], arr[k]);
26+
min = Math.min(min, lcm);
27+
}
28+
}
29+
}
30+
31+
System.out.println(min);
32+
}
33+
34+
public static int gcd(int a, int b) {
35+
while (b != 0) {
36+
int temp = b;
37+
b = a % b;
38+
a = temp;
39+
}
40+
return a;
41+
}
42+
43+
public static int lcm(int a, int b) {
44+
return (a * b) / gcd(a, b);
45+
}
46+
47+
public static int lcm(int a, int b, int c) {
48+
return lcm(lcm(a, b), c);
49+
}
50+
51+
}

0 commit comments

Comments
 (0)