Skip to content

Instantly share code, notes, and snippets.

@heejune
Created June 4, 2017 15:27
Show Gist options
  • Save heejune/6b0be3b094264b6cdcb1a1a965f98b97 to your computer and use it in GitHub Desktop.
Save heejune/6b0be3b094264b6cdcb1a1a965f98b97 to your computer and use it in GitHub Desktop.
bool isPrime(unsigned long num)
{
if (num == 2)
return true;
if (num <= 1 || num % 2 == 0) // 0, 1, and all even numbers
return false;
for (unsigned long x = 3; x*x <= num; x += 2) {
if (num % x == 0)
return false;
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment