Math Homework
Time limit1sMemory limit1024 MB
Construct a sequence of N integers in [1, 10^9] so that the GCD of each given subarray equals a given value at most 16, or report impossibility.
- Level
Hard8 of 10
- Topics
- Number theory, Math, Segment tree, Greedy
- Solved
- No attempts yet
Problem
Your math teacher has given you an assignment involving coming up with a sequence of integers , such that for each .
The sequence must also satisfy requirements, with the th one stating that the GCD (Greatest Common Divisor) of the contiguous subsequence () must be equal to . The GCD of a sequence of integers is the largest integer such that all the numbers in the sequence are divisible by .
Find any valid sequence consistent with all of these requirements, or determine that no such sequence exists.
Input
The first line contains two space-separated integers, and .
The next lines each contain three space-separated integers, , , and ().
Output
If no such sequence exists, output the string Impossible on one line. Otherwise, on one line, output space-separated integers, forming the sequence . If there are multiple possible valid sequences, any valid sequence will be accepted.
Constraints
- for each