CodeForces - 1194A : Remove a Progression

题目链接: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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值