## 原始题面

### Description

Consider an infinite full binary search tree (see the figure below), the numbers in the nodes are 1, 2, 3, .... In a subtree whose root node is X, we can get the minimum number in this subtree by repeating going down the left node until the last level, and we can also find the maximum number by going down the right node. Now you are given some queries as "What are the minimum and maximum numbers in the subtree whose root node is X?" Please try to find answers for there queries

### Input

In the input, the first line contains an integer N, which represents the number of queries. In the next N lines, each contains a number representing a subtree with root number X ($$1 \leqslant X \leqslant 2^{31} - 1$$)

### Output

There are N lines in total, the i-th of which contains the answer for the i-th query

### Source

POJ Monthly,Minkerui

## 解题思路

• 最小结点编号即为根编号对应二进制位中将最低位的 1 换为 0+1 的值

如: 12 -> 110010 -> 1010, 对应的最小结点编号均为 9 -> 1001

• 最大结点编号即为根编号对应二进制位中将最低位的 1 后面的 0 全部变为 1 的值

如: 12 -> 110014 -> 1110, 对应的最大结点编号均为 15 -> 1111

• 最小结点编号即为 x - lowbit(x) + 1
• 最大结点编号即为 x + lowbit(x) - 1

Show code