Skip to content

Instantly share code, notes, and snippets.

@kjensenxz
Last active November 5, 2016 15:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kjensenxz/2a48011089bcdbf8ebac49ef0000eaee to your computer and use it in GitHub Desktop.
Save kjensenxz/2a48011089bcdbf8ebac49ef0000eaee to your computer and use it in GitHub Desktop.
/dpt/ told me to
#include <math.h>
int isPrime(int n) {
int mask = n >> 31;
n = (mask ^ n) - mask;
if (n < 4) return 1;
else if (!(n & 1)) return 0;
unsigned short i;
for (i = 3; i <= sqrt(n); i+=2) {
if (n % i == 0) return 0;
}
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment