Skip to content

Instantly share code, notes, and snippets.

@andytill
Created November 6, 2012 21:48
Show Gist options
  • Select an option

  • Save andytill/4027819 to your computer and use it in GitHub Desktop.

Select an option

Save andytill/4027819 to your computer and use it in GitHub Desktop.
public class Math {
public static boolean isPrime(final long number) {
if (number == 2)
return true;
if (number < 2)
return false;
if(number % 2 == 0)
return false;
long maxCheck = (long) Math.sqrt(number);
for (long i = 3; i <= maxCheck; i += 2) {
if (number % i == 0)
return false;
}
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment