[Solution] Permutation GCD CodeChef Solution
Problem
Chef is interested in the sum of GCDs of all prefixes of a permutation of the integers .
Formally, for a permutation of , let us define a function . Chef is interested in the value of .
Now, Chef wants to find a permutation of which has the given sum equal to . Please help Chef find one such permutation. In case there is no such permutation, print . In case of multiple answers, any of them will be accepted.
A permutation of is a sequence of numbers from to in which each number occurs exactly once.
Input Format
- The first line of input will contain a single integer , denoting the number of test cases.
- Each test case consists of a single line containing two space separated integers and denoting the length of required permutation and the required sum of GCDs of all prefixes respectively.
Output Format
- If there is a valid permutation that satisfies the required condition, then:
- In a single line, output space-separated integers denoting the required permutation permutation.
- If there is no permutation, print in a single line.
Explanation:
Test case : The only possible permutation has a sum of , as required.
Test case : The two permutations of length are:
- with a value of
- with a value of
None of them have a sum of , so we output .
Test case : For , we have:
The sum of these values is , as required.
No comments:
Post a Comment