I think i have checked all the cases (hopefully)
Can anyone help me please ?
Code: Select all
#include <iostream>
#include<cstdio>
using namespace std;
static int n;
static int data [17];
static bool used[17];
static bool Prime[17];
void test (int k)
{
for (int i = 2; i <= n; i++)
if (used[i] == false && Prime [i+data[k-1]])
{
data[k] = i;
used[i] = true;
if (k == n)
{
if (Prime [data[k] + data[1]])
{
for(int i=1;i<n;i++)
printf("%d ",data[i]);
printf("%d\n",data[n]);
}
}
else
test (k+1);
used[i] = false;
}
}
int main ()
{
Prime[2] = true;
Prime[3] = true;
Prime[5] = true;
Prime[7] = true;
Prime[11] = true;
Prime[13] = true;
Prime[17] = true;
Prime[19] = true;
Prime[23] = true;
Prime[29] = true;
Prime[31] = true;
int c = 0;
while (cin >> n)
{
if (c != 0)
printf("\n");
c++;
printf("Case %d:\n",c);
if (n == 1)
cout << "1\n";
else
{
for (int i = 1; i <= 16; i++)
used[i] = false;
data[1] = 1;
used[1] = true;
test (2);
}
}
}