DMOPC '21 Contest 5 P6 - Permutations & Primes

View as PDF

Submit solution


Points: 25 (partial)
Time limit: 2.0s
Memory limit: 256M

Author:
Problem types

Given an integer N, find the lexicographically smallest permutation p1,p2,,pN of 1,2,,N such that i+pi is prime for all 1iN, or report that no such permutation exists.

Constraints

1N106

Subtask 1 [5%]

1N10

Subtask 2 [25%]

1N100

Subtask 3 [15%]

1N103

Subtask 4 [30%]

1N104

Subtask 5 [25%]

No additional constraints.

Input Specification

The first and only line of input contains a single integer N.

Output Specification

If no such permutation exists, output 1 on a line by itself. Otherwise, output N space-separated integers p1,p2,,pN, the lexicographically smallest permutation such that i+pi is prime for all 1iN.

Sample Input

Copy
3

Sample Output

Copy
1 3 2

Explanation

Note that 1+p1=1+1=2, 2+p2=2+3=5, and 3+p3=3+2=5 are all prime.


Comments

There are no comments at the moment.