DMOPC '21 Contest 5 P2 - Permutations & Primes

View as PDF

Submit solution


Points: 7
Time limit: 2.0s
Memory limit: 256M

Author:
Problem type

Given an integer N, find any permutation p1,p2,,pN of 1,2,,N such that p1+p2++pi1+pi is not prime for every integer 1iN, or report that no such permutation exists.

Constraints

1N106

Input Specification

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

Output Specification

If there exists no valid permutation, output 1 on a line by itself.

Otherwise, output N space-separated integers on a single line, representing a permutation p1,p2,,pN of 1,2,,N where no prefix sum is prime.

Sample Input

Copy
5

Sample Output

Copy
4 5 3 2 1

Explanation

The prefix sums are: p1=4, p1+p2=9, p1+p2+p3=12, p1+p2+p3+p4=14, and p1+p2+p3+p4+p5=15.

None of 4, 9, 12, 14, or 15 are prime, so this is a valid permutation.


Comments

There are no comments at the moment.