mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-09 03:59:38 +08:00
optimization
This commit is contained in:
@ -27,7 +27,7 @@ public class PrimeCheck {
|
|||||||
if (n < 2 || n % 2 == 0) {
|
if (n < 2 || n % 2 == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (int i = 3; i <= Math.sqrt(n); i += 2) {
|
for (int i = 3, limit = (int) Math.sqrt(n); i <= limit; i += 2) {
|
||||||
if (n % i == 0) {
|
if (n % i == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user