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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With