Skip to content

Instantly share code, notes, and snippets.

@heejune

heejune/isprime.cpp

Created Jun 4, 2017
Embed
What would you like to do?
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
You can’t perform that action at this time.