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

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<bits/stdc++.h>
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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值