Skip to content

Commit

Permalink
Don't create primes unless needed. Closes #9.
Browse files Browse the repository at this point in the history
  • Loading branch information
hypirion committed Apr 6, 2013
1 parent e1ef73e commit 8970e56
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/java/com/hypirion/Primes.java
Expand Up @@ -86,9 +86,7 @@ public static boolean isPrime(long n){
return false;

int sqrt = (int) Math.sqrt(n);
createAllUnder(sqrt+1);

for (int prime : primeList) {
for (int prime : PRIME) {
if (sqrt < prime)
break;
else if (n % prime == 0)
Expand All @@ -106,9 +104,8 @@ public static List<Long> factorize(long n) {
}

int sqrt = (int) Math.sqrt(n);
createAllUnder(sqrt+1);

for (int prime : primeList) {
for (int prime : PRIME) {
if (n == 1 || sqrt < prime)
break;
else {
Expand Down

0 comments on commit 8970e56

Please sign in to comment.