#P7207. Bitwise Matching Pairs
Bitwise Matching Pairs
Bitwise Matching Pairs
Given two positive integers \(N\) and \(M\), construct two sets:
\(A = \{0,1,2,\ldots, N-1\}\) and \(B = \{M, M+1, \ldots, M+N-1\}\).
Your task is to select \(N\) ordered pairs \((x_i, y_i)\) satisfying the following conditions:
- \(x_i \in A\) and \(y_i \in B\);
- \(x_i \,\&\, y_i = x_i\) (where \(\&\) denotes the bitwise AND operation);
- All \(x_i\) are distinct and all \(y_i\) are distinct.
If a valid pairing exists, output the pairs in increasing order of \(x_i\) (one pair per line). Otherwise, output -1.
inputFormat
The input consists of two positive integers \(N\) and \(M\) separated by a space.
outputFormat
If a valid pairing exists, output \(N\) lines. Each line contains two integers \(x_i\) and \(y_i\) separated by a single space, with the pairs sorted in increasing order of \(x_i\). If no valid pairing exists, output -1.
sample
1 1
0 1