Highly Composite Permutations
InterviewTime limit2sMemory limit512 MB
Find a permutation of 1 to n whose every prefix sum is a composite number, or report that none exists.
- Level
Medium5 of 10
- Topics
- Math, Number theory, Greedy, Implementation
- Solved
- No attempts yet
Problem
A positive integer is called composite if it has strictly more than two positive integer divisors. For example, 4, 30 and 111 are composite, while 1, 7 and 239 are not.
An integer sequence is called a permutation of length if it contains every integer from 1 to inclusive exactly once.
A permutation is called highly composite if for every from 1 to inclusive, the sum of the first elements of , that is , is composite.
Given a single integer , find a highly composite permutation of length .
Input
The only line of the input contains a single integer ().
Output
If no highly composite permutation of length exists, output a single integer . Otherwise, output integers such that is a highly composite permutation.
If there are multiple highly composite permutations of length , you may output any of them.
Notes
In the first example test case, the first element of the permutation, 9, is composite, the sum of the first two elements, , is composite, the sum of the first three elements, , is composite, and so on.
In the second example test case, only two permutations of the required length exist, and , and neither of them is highly composite.