DMOPC '21 Contest 5 P6 - Permutations & Primes
View as PDFGiven an integer , find the lexicographically smallest permutation 
 of 
 such that 
 is prime for all 
, or report that no such permutation exists.
Constraints
Subtask 1 [5%]
Subtask 2 [25%]
Subtask 3 [15%]
Subtask 4 [30%]
Subtask 5 [25%]
No additional constraints.
Input Specification
The first and only line of input contains a single integer .
Output Specification
If no such permutation exists, output  on a line by itself. Otherwise, output 
 space-separated integers 
, the lexicographically smallest permutation such that 
 is prime for all 
.
Sample Input
3
Sample Output
1 3 2
Explanation
Note that , 
, and 
 are all prime.
Comments