Restore Sequence codechef november long challenge problem solution -
Alice has a very complex machine ― when fed with a sequence , it produces a sequence , where for each valid , is the largest index such that divides (since divides itself, such an index always exist). For example, if the machine is fed with , it produces .
Alice gave you a sequence that was produced by the machine. Find an integer sequence such that when it is fed into the machine, then the machine produces the sequence . Alice does not like huge integers, so make sure that holds for each valid .
Input
- The first line of the input contains a single integer denoting the number of test cases. The description of test cases follows.
- The first line of each test case contains a single integer .
- The second line contains space-separated integers .
Output
For each test case, print a single line containing space-separated integers . For each valid , should hold.
If there are multiple solutions, you may print any of them. It is guaranteed that at least one solution exists.
Constraints
- for each valid
- the sum of over all test cases does not exceed
Subtasks
Subtask #1 (20 points): are pairwise distinct
Subtask #2 (80 points): original constraints
Example Input
2
5
5 2 3 4 5
4
4 4 4 4
Example Output
2 6 5 3 4
2 6 3 12
link-https://www.codechef.com/NOV20B/problems/RESTORE
Restore Sequence codechef Solution -
Comments
Post a Comment