To be honest, this question is really not done, and there are some ideas, but there are problems that cannot be solved, and then others provide ideas.
Not much to mention ....
This question requires the formation of a ring. The sum of no two adjacent numbers cannot be prime numbers. Of course, the last one should consider the relationship between them and the first one. In fact, the DFS here only needs to recursion, what I do with recursion is always wrong. It is mainly affected by the deformation class. Actually, recursion is definitely the current number, and the current number is stored in the array, so that the next recursion can be compared with the number of this time ....
# Include <stdio. h> # include <string. h> int N, num [25], des [25]; int gcd (int n) {int f = 0; If (n = 2 | n = 3) return 1; for (INT I = 2; I <= n/2; ++ I) if (N % I = 0) return 0; return 1 ;} void DFS (int x) {If (x = N & gcd (Num [N] + 1) // when the last one arrives {for (INT I = 1; I <= N; ++ I) printf (I = 1? "% D": "% d", num [I]); // puts ("");} else {for (INT I = 2; I <= N; ++ I) {If (! Des [I] & gcd (I + num [x]) // find the number of matching conditions {des [I] = 1; // memory num [x + 1] = I; DFS (x + 1); des [I] = 0; // backtracking }}} int main () {int T = 0; while (scanf ("% d", & N )! = EOF) {memset (Num, 0, sizeof (Num); memset (DES, 0, sizeof (DES); des [1] = num [1] = 1; printf ("case % d: \ n", ++ T); DFS (1); puts ("") ;}return 0 ;}