Linear Algebra: Concepts and Methods
Time limit2sMemory limit1024 MB
Given N, find a permutation of 1 to N where max minus min is not prime for every contiguous part of length at least 2, or report that none exists.
- Level
Medium7 of 10
- Topics
- Math, Number theory, Implementation
- Solved
- No attempts yet
Problem
Tired of studying linear algebra, the students of KSA came up with the following problem.
Given an integer , determine whether a sequence satisfying the following conditions exists, and if one exists, find any such sequence.
- The sequence is a permutation of length . That is, each integer from to appears exactly once.
- For every contiguous subsequence of the sequence with length at least , the value of is not prime.
A sequence is called a contiguous subsequence of a sequence if can be obtained by removing zero or more elements from the front of and zero or more elements from the back of .
However, the KSA students have an illness that prevents them from telling primes apart, so they asked you to solve this problem.
Input
The first line contains an integer .
Output
On the first line, print YES if a sequence satisfying the conditions exists, and NO otherwise.
If such a sequence exists, print integers separated by spaces on the second line.
If multiple answers exist, you may print any of them.