Deep Search-Prime ring

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.