首页 > 其他分享 >CF1194A - Remove a Progression

CF1194A - Remove a Progression

时间:2022-09-18 00:03:13浏览次数:95  
标签:CF1194A Progression algorithm number Remove numbers th 测试点

CF1194A - Remove a Progression

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

img

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\) 个(注意,是将数字整个擦除,而不是只擦除其中的一位)。

img

你的行动直到黑板上剩余的数字个数少于 \(i\) 时停止。

现在你想知道:当你停止行动时,黑板上剩余的第 \(x\) 个数字是几?

输入

第一行是一个整型 \(T\) \((1≤T≤100)\) ,代表测试点个数。接下来 \(T\) 行每一行一个测试点,每个测试点都是独立的。

每一行有被空格分开的两个数 \(n\) 和 \(x\) \((1≤x<n≤109)\)。\(n\) 是数字的最初个数,而 \(x\) 是你想知道的位置。数据保证行动结束时黑板上剩下不少于 \(x\) 个数字。

输出

对每个测试点输出位置 \(x\) 的值。

样例

输入

3
3 1
4 2
69 6

输出

2
4
12

官方题解

After some simulation of the given algorithm (in your head, on paper or on a computer) we can realize that exactly all odd numbers are erased. So, all even numbers remain, and the answer is \(2x\).

官方题解翻译

用各种方法(比如在你的脑子里,或者在纸上,或者在电脑里)模拟后,我们发现所有的奇数位置的数字全被擦除了,只有偶数位置的数剩下。所以答案是 \(2x\)。

个人 AC 代码

#include <bits/stdc++.h>
using namespace std;

const int N = 1e9+2;
int t, n, x;

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> t;
    while(t--)
    {
        cin >> n >> x;
        cout << 2*x << '\n';
    }
    return 0;
}

标签:CF1194A,Progression,algorithm,number,Remove,numbers,th,测试点
From: https://www.cnblogs.com/CasseShimada/p/16703974.html

相关文章