Skip to content

Instantly share code, notes, and snippets.

@halferty
Created February 17, 2015 04:22
Show Gist options
  • Select an option

  • Save halferty/788d0e9d3e0365a949b7 to your computer and use it in GitHub Desktop.

Select an option

Save halferty/788d0e9d3e0365a949b7 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
int isPrime(int64_t);
int main(int argc, char *argv[]) {
int64_t testPrime = 0xffffffffffffffc5LL;
printf("%d", isPrime(testPrime));
return 0;
}
int isPrime(int64_t n){
if (n%2==0) return n==2;
if (n%3==0) return n==3;
int d=5;
while(d*d<=n){
if(n%d==0) return 0;
d+=2;
if(n%d==0) return 0;
d+=4;}
return 1;}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment