Created
February 17, 2015 04:22
-
-
Save halferty/788d0e9d3e0365a949b7 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
| #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