public int[] solution(int e, int[] starts) {
int[] numbers = new int[e + 1];
int[] answer = new int[starts.length];
for (int i = 1; i <= e; i++) {
for (int j = i; j <= e; j += i) {
numbers[j] += 1;
}
}
int[] maxNumber = new int[e + 1];
Arrays.fill(maxNumber, e);
for (int i = e - 1; i > 0; i--) {
maxNumber[i] = (numbers[i] >= numbers[maxNumber[i + 1]]) ? i : maxNumber[i + 1];
}
for (int i = 0; i < starts.length; i++) {
answer[i] = maxNumber[starts[i]];
}
return answer;
}
출처:https://school.programmers.co.kr/learn/courses/30/lessons/138475