http://acm.hdu.edu.cn/showproblem.php?pid=1016
#include <cstdio>
#include <cstring>
using namespace std;
int prime[40]={0};
int n,count;
int ans[21];
int vis[21];
void dfs(int x)
{
if(count==n&&!prime[ans[0]+ans[n-1]])
{
printf("%d",ans[0]);
for(int i = 1; i<n; i++)
printf(" %d",ans[i]);
printf("\n");
}
for(int i = 2; i<=n; i++)
if(!prime[x+i]&&!vis[i])
{
vis[i]=1;
ans[count++]=i;
dfs(i);
count--;
vis[i]=0;
}
}
int main()
{
for(int i = 2; i<40; i++)
if(!prime[i])
for(int j = i+i; j<40; j+=i)
prime[j]=1;
int k = 1;
while(scanf("%d",&n)!=EOF)
{
count=1;
memset(vis,0,sizeof(vis));
ans[0]=1;
printf("Case %d:\n",k);
dfs(1);
printf("\n");
k++;
}
}