Flexible Segments
Time limit1sMemory limit512 MB
For each n up to 10000, decide whether some n consecutive positive integers admit a +1/-1 choice per element preserving the product, and output the start and signs.
- Level
Hard8 of 10
- Topics
- Number theory, Math, Greedy, Implementation
- Solved
- No attempts yet
Problem
The great mathematician Vladimir Germanovich noticed an interesting property of some segments of positive integers while searching for new patterns.
Vladimir calls the segment of positive integers flexible if he can change every number of this segment by exactly one in such a way that the product of the numbers in the segment does not change. That is, there exists a sequence with the following properties:
Now Vladimir Germanovich wants to know whether he can build a flexible segment of any length. Given a positive integer , find any flexible segment consisting of consecutive positive integers, or report that no such segment exists.
Input
The only line contains an integer (), the length of the required segment.
Output
The first line of output must contain "YES" if a flexible segment of positive integers exists. Otherwise it must contain "NO".
If such a segment exists, the second and third lines must contain the description of this segment.
The second line should contain the only integer (), the first element of this segment. It is guaranteed that if a flexible segment of length exists, then there exists a flexible segment of length such that .
The third line should contain a string of length without spaces. It must consist of "+" and "-" characters. The -th character of this string should be "-" if , or "+" if .
Hint
In the second example, , , . The answer is as follows: , , , . The product of the integers from to is . The product of the is . Thus, the segment is flexible.