Created
June 4, 2017 15:27
-
-
Save heejune/6b0be3b094264b6cdcb1a1a965f98b97 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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