Remove a Progression

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?

Input
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.

Each line contains two space-separated integers n and x (1≤x

Output
Print T integers (one per query) — the values of the x-th number after performing the algorithm for the corresponding queries.

Example

input

3
3 1
4 2
69 6

output

2
4
12

题意:一个从 1 到 n 的数组,i 从 1 开始每次删除第 i 个数字,然后 i 自增,,知道剩余数字不足 i 个为止,输出第 x 个数字。

分析问题可以发现,该过程是把数组中所有的奇数删除了,所以答案应该是 x*2。

我竟然傻乎乎的开始模拟了,我的天哪,我这是怎么了!!!

这教育我们,写题之前先分析问题,分析完问题再去解决!!!!

#include
using namespace std;
#define endl "\n"
list<int> arr;
int t, n, x;
int main()
{
#ifdef endl
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);
#endif
	cin >> t;
	while (t--) {
		cin >> n >> x;
		cout << x*2 << endl;
	}
	return 0;
}

你可能感兴趣的:(#,错题集)