1 #include<iostream> 2 #include<memory.h> 3 using namespace std; 4 int n,visit[ 21],cir[ 21],pri[ 40]; 5 void dfs( int k, int n) 6 { 7 int i; 8 if(k == n && pri[ 1 + cir[n- 1]] ) 9 { 10 cout<< 1; 11 for(i = 1; i < n; ++i) 12 cout<< " "<<cir[i]; 13 cout<<endl; 14 } 15 16 else 17 { 18 for(i = 2; i <= n; ++i) 19 { 20 if(pri[i + cir[k- 1]] && !visit[i]) 21 { 22 visit[i] = 1; 23 cir[k] = i; 24 dfs(k+ 1,n); 25 visit[i] = 0; 26 } 27 } 28 } 29 } 30 int main() 31 { 32 pri[ 2] = 1; pri[ 3] = 1; pri[ 5] = 1; pri[ 7] = 1; pri[ 11] = 1;pri[ 13] = 1; 33 pri[ 17] = 1; pri[ 19] = 1; pri[ 23] = 1; pri[ 29] = 1;pri[ 31] = 1; pri[ 37] = 1; 34 int i,j,t= 0; 35 while(cin>>n,n) 36 { 37 cout<< " Case "<<++t<< " :\n "; 38 if(n == 1){ 39 cout<< 1<<endl; 40 continue; 41 } 42 if(n & 1){ 43 cout<< " No Answer\n "; 44 continue; 45 } 46 memset(visit, 0, sizeof(visit)); 47 visit[ 1] = 1; cir[ 0] = 1; 48 dfs( 1,n); 49 } 50 return 0; 51 }