//30/01/21 08:49
#include<bits/stdc++.h>
using namespace std;
#define MAXN 17
bool vis[MAXN],G[MAXN][MAXN],flag;
int cnt=1,graph[MAXN],n;
void my_print();
bool check_if(int x){
if(x<2) return false;
if(x==2) return true;
for(int i=2;i*i<=x;i++){
if(x%i==0) return false;
}
}
void dfs(int x){
if(x==n&&check_if(graph[n-1]+graph[0])){
my_print();
return;
}
for(int i=2;i<=n;i++){
if(!vis[i]&&check_if(i+graph[x-1])){
graph[x]=i;
vis[i]=1;
dfs(x+1);
vis[i]=0;
}
}
}
void my_print(){
for(int i=0;i<n-1;i++){
cout<<graph[i]<<" ";
}
cout<<graph[n-1]<<endl;
}
int main()
{
while(cin>>n){
if(cnt>1) printf("\n");
cout<<"Case "<<cnt<<":"<<endl;
++cnt;
graph[0]=1;
vis[1]=1;
dfs(1);
memset(vis,false,sizeof(vis));
}
return 0;
}
这段代码uva提交之后wa,格式检查过了不知道哪有错啊!!