Created
May 29, 2014 20:15
-
-
Save GeorgiPachov/89db786c2ba9efc651e3 to your computer and use it in GitHub Desktop.
getSmallestMultiple
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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