Title Description
Description
A prime ring of size n (n<=17) is a number ring consisting of 1 to N of a total of n natural numbers, and the sum of each of the two contiguous numbers on a number of rings is prime. As a prime-number ring of size 6. For convenience of description, the first digit on the number ring is always 1. If available 1 4 3 2 5 6来 description. If the two prime number rings, the numbers are arranged in the same order as essentially the same. Now ask you to find all the different rings of the essence.
Enter a description
Input Description
There is only one number n, which represents the size of the required prime ring. Such as:
Output description
Output Description
Each line describes a number loop, and if there are multiple sets of solutions, the output is from small to large in dictionary order. Such as:
Sample input
Sample Input
6
Sample output
Sample Output
1 4 3 2 5 6
1 6 5 2 3 4
Data range and Tips
Data Size & Hintn<=17//ideas: Sieve method to build the prime table, recursive push, array record order and remove the selected, the code is as follows
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm>using namespace Std;int Su[50],a,b,m,n,huan[20],shu[20];int Shai () {int i,j;for (i=2;i<50;i++) if (su[i]==0) {j=i*2;while (j<50) Su[j]=1,j+=i;} return 0;} int print () {int i,j;for (i=1;i<=n;i++) cout<
Deep Search-Prime ring