Question: time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output You are given a set of n (n is always a

time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output You are given a set of n (n is always a power of 2) elements containing all integers 0,1,2,,n1 exactly once.

Find n2 pairs of elements such that:

Each element in the set is in exactly one pair. The sum over all pairs of the bitwise AND of its elements must be exactly equal to k. Formally, if ai and bi are the elements of the i-th pair, then the following must hold: i=1n/2ai&bi=k, where & denotes the bitwise AND operation. If there are many solutions, print any of them, if there is no solution, print 1 instead.

Input The input consists of multiple test cases. The first line contains a single integer t (1t400) the number of test cases. Description of the test cases follows.

Each test case consists of a single line with two integers n and k (4n216, n is a power of 2, 0kn1).

The sum of n over all test cases does not exceed 216. All test cases in each individual input will be pairwise different.

Output For each test case, if there is no solution, print a single line with the integer 1.

Otherwise, print n2 lines, the i-th of them must contain ai and bi, the elements in the i-th pair.

If there are many solutions, print any of them. Print the pairs and the elements in the pairs in any ordertime limit per test1 second memory limit per test256 megabytes inputstandard input

Example input Copy 4 4 4 1 4 2 4 3 output Copy 03 1 2 02 1 3 0 1 23 -1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!