Problems
Perfect match
Perfect match
You are given two integers n and m. Construct such pairs (x, y) from sets A = {0, 1, 2, ..., n − 1} and B = {m, ..., m + n − 1} so that all pairs (x, y) (x ∈ A and y ∈ B) satisfies the condition x & y = x (Here & stands for the bitwise AND operation)
Input
Two integers n and m (1 ≤ n ≤ m, n + m ≤ 106
).
Output
Print n lines. In the line i print two integers xi
and yi
. xi
must be in A and yi
in B. Each of these pairs that you output must be a matching pair, as specified in the problem statement.
- 0 ≤
xi
≤ n − 1 and for any i ≠ j should bexi
≠xj
- m ≤
yi
≤ m + n − 1 and for any i ≠ j should beyi
≠yj
Note
It can be proved that a solution always exists.
Input example #1
3 4
Output example #1
0 4 1 5 2 6
Input example #2
6 7
Output example #2
0 8 1 9 2 10 3 11 4 12 5 7