[Solution] Mainak and Interesting Sequence Codeforces Solution
Mainak has two positive integers and .
Mainak finds a sequence of positive integers interesting, if for all integers (), the bitwise XOR of all elements in which are strictly less than is . Formally if is the bitwise XOR of all elements in which are strictly less than , then is an interesting sequence if .
For example, sequences , , are interesting, whereas (), (), () aren't interesting.
Here denotes bitwise XOR of integers and .
Find any interesting sequence (or report that there exists no such sequence) such that the sum of the elements in the sequence is equal to , i.e. .
As a reminder, the bitwise XOR of an empty sequence is considered to be .
Each test contains multiple test cases. The first line contains a single integer () — the number of test cases. Description of the test cases follows.
The first line and the only line of each test case contains two integers and (, ) — the length of the sequence and the sum of the elements.
It is guaranteed that the sum of over all test cases does not exceed .
For each test case, if there exists some interesting sequence, output "Yes" on the first line, otherwise output "No". You may print each letter in any case (for example, "YES", "Yes", "yes", "yEs" will all be recognized as positive answer).
If the answer is "Yes", output positive integers (), forming an interesting sequence such that . If there are multiple solutions, output any.
- In the first test case, is the only interesting sequence of length having sum .
- In the third test case, there is no sequence of length having sum of elements equal to , so there is no such interesting sequence.
- In the fourth test case, , because bitwise XOR of an empty sequence is .
No comments:
Post a Comment