Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print sequences with prime sum

Tags:

Given an integer n, I want to find two permutations of the numbers 1 to n (inclusive) such that the sum of numbers from the two permutations at any given index is always prime.

For example:

   n = 5

      1 2 3 4 5
      1 5 4 3 2

   n = 8

      1 2 3 4 5 6 7 8
      2 1 4 3 8 7 6 5
like image 205
Prashanth Kumar Avatar asked May 28 '20 11:05

Prashanth Kumar


1 Answers

Construct a bipartite graph on {0,1} x {1...n} such that (0, i) and (1, j) are connected if and only if i+j is prime.

Find a perfect matching using any standard technique, and then produce the sequences so that the matching numbers are at the same index.

like image 159
Paul Hankin Avatar answered Oct 02 '22 17:10

Paul Hankin