We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b6b953d commit 46475d0Copy full SHA for 46475d0
src/com/codefortomorrow/intermediate/chapter11/solutions/IsPrime.java
@@ -30,9 +30,9 @@ public static boolean isPrime(int number) {
30
return false;
31
}
32
33
- // only need to check divisors up to number / 2
+ // only need to check divisors up to sqrt(number)
34
// because after that the factors "repeat"
35
- for (int divisor = 2; divisor <= number / 2; divisor++) {
+ for (int divisor = 2; divisor <= Math.sqrt(number); divisor++) {
36
if (number % divisor == 0) { // primes only divisible by 1 and itself
37
return false; // number isn't a prime
38
0 commit comments