Created
December 26, 2012 05:57
-
-
Save anonymous/4378259 to your computer and use it in GitHub Desktop.
n^2 - 2. Is it prime?
This file contains 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 <iostream> | |
using namespace std; | |
#define MAX 100 | |
bool isPrime(const int i) | |
{ | |
if (i <= 1) return false; | |
int j; | |
for(j = 2; j*j <= i; j++) | |
if(0 == i%j) return false; | |
return true; | |
} | |
int main(void) | |
{ | |
bool p; | |
char c; | |
int n2; | |
int odd; | |
for (odd = 3; odd < MAX; odd += 2) | |
{ | |
n2 = (odd * odd) - 2; | |
p = isPrime(n2); | |
c = p ? ' ' : '*'; | |
cout << odd << " : " << n2 << " " << c << " " << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment