Skip to content

Instantly share code, notes, and snippets.

@lifeparticle
Last active May 16, 2023 12:02
Show Gist options
  • Save lifeparticle/c17f2c9727398c7e1493e57f67c75322 to your computer and use it in GitHub Desktop.
Save lifeparticle/c17f2c9727398c7e1493e57f67c75322 to your computer and use it in GitHub Desktop.
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