public int solution(int[] arr) {
int answer = arr[0];
for (int i = 1; i < arr.length; i++) {
answer = lcm(answer, arr[i]);
}
return answer;
}
public int lcm(int x, int y) {
return x * y / gcd(x, y);
}
public int gcd(int x, int y) {
int a = Math.max(x, y);
int b = Math.min(x, y);
while (a % b != 0) {
int r = a % b;
a = b;
b = r;
}
return b;
}
출처:https://school.programmers.co.kr/learn/courses/30/lessons/12953