anonymous / n2 primer.cpp
Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

n^2 - 2. Is it prime?

View n2 primer.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
#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
Something went wrong with that request. Please try again.