import java.util.Scanner;
public class Main1016 {
public static void main(String[] args) {
Scanner cin=new Scanner(System.in);
int k=1;
while(cin.hasNext()){
int n=cin.nextInt();
int []a=new int [n];
int []color=new int [n];
for(int i=0;i<n;i++){
a[i]=i+1;
color[i]=-1;
}
//System.out.println("------------------");
//print(a);
int []parent=new int [n];
int count=0;
System.out.println("Case "+(k++)+":");
dfs(a,parent,color,0,count);
System.out.println();
}
}
private static void dfs(int[] a, int[] parent, int[] color, int g, int count) {
count++;
if(count==a.length&&isprime(a[g]+a[0])){
parent[count-1]=a[g];
print(parent);
return;
}
color[g]=1;
for(int s=0;s<a.length;s++){
if(color[s]==-1&&isprime(a[s]+a[g])){
parent[count-1]=a[g];
dfs(a,parent,color,s,count);
color[s]=-1;
}
}
}
private static boolean isprime(int i) {
for(int j=2;j*j<=i;j++){
if(i%j==0)
return false;
}
return true;
}
private static void print(int[] parent) {
for(int j=0;j<parent.length-1;j++){
System.out.print(parent[j]+" ");
}
System.out.println(parent[parent.length-1]);
}
}
这是一道简单的深搜题目。