问题描述:
You have a list of numbers from 1 to n written from left to right on the blackboard.
You perform an algorithm consisting of several steps (steps are 1-indexed). On the i-th step you wipe the i-th number (considering only remaining numbers). You wipe the whole number (not one digit).
When there are less than i numbers remaining, you stop your algorithm.
Now you wonder: what is the value of the x-th remaining number after the algorithm is stopped?
(翻译:黑板上有从左到右从1到n的数字列表。
执行一个由多个步骤组成的算法(步骤为1索引)。在第i步中,删除第i个数字(只考虑剩余的数字)。你擦掉整个数字(不是一个数字)。
当剩下的数字少于i时,停止您的算法。
现在你想知道:算法停止后,第x个剩余数字的值是多少?
)
输入内容:
The first line contains one integer T (1≤T≤100) — the number of queries. The next T lines contain queries — one per line. All queries are independent.(第一行包含一个整数t(1≤t≤100)-查询数。接下来的T行包含查询-每行一个。所有查询都是独立的。)
Each line contains two space-separated integers n and x (1≤x<n≤109) — the length of the list and the position we wonder about. It's guaranteed that after the algorithm ends, the list will still contain at least x numbers.(每行包含两个空格分隔的整数n和x(1≤x<n≤109)-列表的长度和我们想知道的位置。它保证在算法结束后,列表仍然包含至少x个数字。)
输出内容:
Print T integers (one per query) — the values of the x-th number after performing the algorithm for the corresponding queries.(打印T整数(每个查询一个)-执行相应查询的算法后的第x个数字的值。)
样例:
3
3 1
4 2
12 6
过程:
1:第一个结果:
当n=3,x=1时:
原始数字:1、2、3
第一步,去掉第一个数字:2、3
第二步,去掉第二个数字:2(只剩x=1个数字)
第x=1个数为:2。
2:第二个结果:
当n=4,x=2时:
原始数字:1、2、3、4
第一步,去掉第一个数字:2、3、4
第二步,去掉第二个数字:2、4(只剩x=2个数字)
第x=2个数为:4。
3:第三个结果:
当n=12,x=6时:
原始数字:1、2、3、4、5、6、7、8、9、10、11、12
第一步,去掉第一个数字: 2、3、4、5、6、7、8、9、10、11、12
第二步,去掉第二个数字:2、4、5、6、7、8、9、10、11、12
第三步,去掉第三个数字:2、4、6、7、8、9、10、11、12
第四步,去掉第四个数字:2、4、6、8、9、10、11、12
第五步,去掉第五个数字:2、4、6、8、10、11、12
第六步,去掉第六个数字:2、4、6、8、10、12(只剩x=6个数字)
第x=6个数为:12。
可以看出:每次删掉的都是奇数,且依次从1、3、5、7……开始删,最终剩下的第x个数为2x,所以这道题超级简单
代码如下: