/*
终究是自己弱爆了~~~
简单的DFS 写了那么久;
*/
/*
*Author ID:fuqiang11
*Problem ID:HDU 1016
*Submit Time:2013/7/22
*Algorithm :DFS
*/
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cstring>
using namespace std;
#define maxn 20
bool visit[maxn];
int pre[maxn];
int n;
bool is_primer(int a) //判断素数
{
for(int i = 2; i <= sqrt(a); i++)
if(a%i == 0)
return false;
return true;
}
void prin_pre(int x) //打印路径
{
if(x == 1)
printf("1");
else
{
prin_pre(pre[x]);
printf(" %d",x);
}
}
void DFS(int st, int len)
{
if(len == n) //达到n个
{
if(is_primer(st + 1)) //能构成环
{
prin_pre(st);
printf("\n");
}
}
else
{
for(int i = 1; i <= n; i++)
{
if(!visit[i] && is_primer(st + i))
{
//cout<< st <<" + "<< i <<endl;
visit[i] = true; //访问
pre[i] = st; //前驱
DFS(i,len+1);
visit[i] = false; //回溯
}
}
}
return ;
}
int main()
{
int Case = 1;
while(scanf("%d",&n)!=EOF)
{
memset(visit,false,sizeof(visit));
visit[1] = true;
pre[1] = 1;
printf("Case %d:\n",Case++);
DFS(1,1);
printf("\n");
}
return 0;
}