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 p_1, p_2, \dots, p_N of 1, 2, \dots, N such that i+p_i is prime for all 1 \le i \le N, or report that no such permutation exists.

Constraints

1 \le N \le 10^6

Subtask 1 [5%]

1 \le N \le 10

Subtask 2 [25%]

1 \le N \le 100

Subtask 3 [15%]

1 \le N \le 10^3

Subtask 4 [30%]

1 \le N \le 10^4

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 p_1, p_2, \dots, p_N, the lexicographically smallest permutation such that i+p_i is prime for all 1 \le i \le N.

Sample Input

3

Sample Output

1 3 2

Explanation

Note that 1+p_1 = 1+1 = 2, 2+p_2 = 2+3 = 5, and 3+p_3 = 3+2 = 5 are all prime.


Comments

There are no comments at the moment.