Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
getSmallestMultiple
@Override
public long getSmallestMultiple(int upperBound) {
long result = 1;
for (int i = 2; i <= upperBound; i++) {
int[] divisors = getDivisors(i);
int pointer = 0;
while (result%i != 0){
result*=divisors[pointer++];
}
}
return result;
}
private static int[] getDivisors(int number) {
int[] divisors = new int[number];
int pointer = 0;
for (int i = 2; i <= number; i++) {
if (number % i == 0) {
divisors[pointer++] = i;
number /= i;
i--;
}
}
return divisors;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.