题目链接:https://vjudge.net/problem/CodeForces-1194A
题目描述:
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(i从1开始)个数, 并且i增加1直到剩下的数的数量小于i,然后让你输出它的第x个数
这道题其实是一个找规律的题,我们来模拟一下长度为len时最后留下的数的值
设len为数字的长度,n为第n个数, len > n >= 1.
所以len最少是2.
len = 2 :
c 1 : 1 2
c 2 : 2
len = 3
c 1 :1 2 3
c 2 :2 3
c 3 :2
len = 4
c 1 :1 2 3 4
c 2 :2 3 4
c 3 :2 4
…
往后发现每回都只有偶数被留下来,而且第n个数就是2*n
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<string>
#include<vector>
#include<climits>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define max(a, b) (a > b ? a : b)
#define min(a, b) (a < b ? a : b)
#define mst(a) memset(a, 0, sizeof(a))
#define _test printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n")
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const double eps = 1e-7;
const int INF = 0x3f3f3f3f;
const ll ll_INF = 233333333333333;
const int maxn = 1e3 + 10;
int main(void) {
int t;
scanf("%d", &t);
while(t--) {
ll n, k;
scanf("%lld%lld", &n, &k);
printf("%lld\n", 2*k);
}
return 0;
}