分析一下样例(括号里为二进制):
8(1000),8最左端的树叶为1(0001),最右端的树叶为15(1111),恰好是8-7和8+7的结果,而lowbit(8)=8;
10(1010),10最左端的树叶为9(1001),最右端的树叶为11(1011),恰好是10-1和10+1的结果,而lowbit(10)=2;
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.
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 <= X <= 2
31 - 1).
There are N lines in total, the i-th of which contains the answer for the i-th query.
2 8 10
1 15 9 11
#include<stdio.h>
#define lowbit(x) ((x)&(-x))
int main()
{
int n;
scanf("%d",&n);
while(n--)
{
int x,y;
scanf("%d",&x);
y=lowbit(x)-1;
printf("%d %d\n",x-y,x+y);
}
return 0;
}