問(wèn)題描述:
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的數(shù)字列表。
執(zhí)行一個(gè)由多個(gè)步驟組成的算法(步驟為1索引)捶枢。在第i步中薛窥,刪除第i個(gè)數(shù)字(只考慮剩余的數(shù)字)。你擦掉整個(gè)數(shù)字(不是一個(gè)數(shù)字)暖夭。
當(dāng)剩下的數(shù)字少于i時(shí)积蜻,停止您的算法志电。
現(xiàn)在你想知道:算法停止后,第x個(gè)剩余數(shù)字的值是多少拉讯?
)
輸入內(nèi)容:
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.(第一行包含一個(gè)整數(shù)t(1≤t≤100)-查詢(xún)數(shù)涤浇。接下來(lái)的T行包含查詢(xún)-每行一個(gè)。所有查詢(xún)都是獨(dú)立的魔慷。)
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.(每行包含兩個(gè)空格分隔的整數(shù)n和x(1≤x<n≤109)-列表的長(zhǎng)度和我們想知道的位置只锭。它保證在算法結(jié)束后,列表仍然包含至少x個(gè)數(shù)字院尔。)
輸出內(nèi)容:
Print T integers (one per query) — the values of the x-th number after performing the algorithm for the corresponding queries.(打印T整數(shù)(每個(gè)查詢(xún)一個(gè))-執(zhí)行相應(yīng)查詢(xún)的算法后的第x個(gè)數(shù)字的值蜻展。)
樣例:
3
3? 1
4? 2
12? 6
過(guò)程:
1:第一個(gè)結(jié)果:
當(dāng)n=3,x=1時(shí):
原始數(shù)字:1邀摆、2纵顾、3
第一步,去掉第一個(gè)數(shù)字:2栋盹、3
第二步片挂,去掉第二個(gè)數(shù)字:2(只剩x=1個(gè)數(shù)字)
第x=1個(gè)數(shù)為:2。
2:第二個(gè)結(jié)果:
當(dāng)n=4,x=2時(shí):
原始數(shù)字:1贞盯、2、3沪饺、4
第一步躏敢,去掉第一個(gè)數(shù)字:2、3整葡、4
第二步件余,去掉第二個(gè)數(shù)字:2、4(只剩x=2個(gè)數(shù)字)
第x=2個(gè)數(shù)為:4遭居。
3:第三個(gè)結(jié)果:
當(dāng)n=12,x=6時(shí):
原始數(shù)字:1啼器、2、3俱萍、4端壳、5、6枪蘑、7损谦、8、9岳颇、10照捡、11、12
第一步话侧,去掉第一個(gè)數(shù)字: 2栗精、3、4瞻鹏、5悲立、6鹿寨、7、8级历、9释移、10、11寥殖、12
第二步玩讳,去掉第二個(gè)數(shù)字:2、4嚼贡、5熏纯、6、7粤策、8樟澜、9、10叮盘、11秩贰、12
第三步,去掉第三個(gè)數(shù)字:2柔吼、4毒费、6、7愈魏、8觅玻、9、10培漏、11溪厘、12
第四步,去掉第四個(gè)數(shù)字:2牌柄、4畸悬、6、8珊佣、9傻昙、10、11彩扔、12
第五步妆档,去掉第五個(gè)數(shù)字:2、4虫碉、6贾惦、8、10、11须板、12
第六步碰镜,去掉第六個(gè)數(shù)字:2、4习瑰、6绪颖、8、10甜奄、12(只剩x=6個(gè)數(shù)字)
第x=6個(gè)數(shù)為:12柠横。
可以看出:每次刪掉的都是奇數(shù),且依次從1课兄、3牍氛、5、7……開(kāi)始刪烟阐,最終剩下的第x個(gè)數(shù)為2x,所以這道題超級(jí)簡(jiǎn)單
代碼如下: