Even Odds

Even Odds

题面翻译

题目大意

作为一个不顺从的人, V o l o d y a Volodya Volodya 不喜欢当前的事物状态,特别是自然数的顺序(自然数是正整数)。他决心重新安排他们。但是自然数太多,所以 V o l o d y a Volodya Volodya 决定从 n n n 开始。他写出下面的数列:首先是从1到 n n n 的所有奇数整数(以升序排列),然后从1到 n n n 的所有偶数整数(也按升序排列)。帮助我们的英雄找出:第 k k k 个数字是多少

输入输出格式

输入格式:

输入一行包含整数n和k(1 <=k<=n<=10^12)

请不要使用%lld说明符来读取或写入C++中的64位整数。最好使用cin、cut流或%I64d说明符。

翻译提供者:蒟蒻烟雨平生

题目描述

Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first $ n $ . He writes down the following sequence of numbers: firstly all odd integers from $ 1 $ to $ n $ (in ascending order), then all even integers from $ 1 $ to $ n $ (also in ascending order). Help our hero to find out which number will stand at the position number $ k $ .

输入格式

The only line of input contains integers $ n $ and $ k $ ( $ 1<=k<=n<=10^{12} $ ).

Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.

输出格式

Print the number that will stand at the position number $ k $ after Volodya’s manipulations.

样例 #1

样例输入 #1

10 3

样例输出 #1

5

样例 #2

样例输入 #2

7 7

样例输出 #2

6

提示说明

In the first sample Volodya’s sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5.

代码内容

// #include <iostream>
// #include <algorithm>
// #include <cstring>
// #include <stack>//栈
// #include <deque>//队列
// #include <queue>//堆/优先队列
// #include <map>//映射
// #include <unordered_map>//哈希表
// #include <vector>//容器,存数组的数,表数组的长度
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main()
{
    ll n,k;
    cin>>n>>k;
    
    if(n&1) n++;
    if(k<=n/2) cout<<2*k-1<<endl;
    else cout<<2*(k-n/2)<<endl;
    
    return 0;
}



    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Pretty Boy Fox

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值