Last active
May 16, 2023 12:02
-
-
Save lifeparticle/c17f2c9727398c7e1493e57f67c75322 to your computer and use it in GitHub Desktop.
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
public static boolean isPrime(int number) { | |
if (number < 2) | |
return false; | |
if (number == 2 || number == 3) | |
return true; | |
if(number % 2 == 0 || number % 3 == 0) | |
return false; | |
int sqrt = (int) Math.sqrt(number); | |
int dx = 4; | |
for (int i = 5; i <= sqrt; i+=dx) { | |
if (number % i == 0) | |
return false; | |
dx = - (dx - 6); | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment