Codeforces Round #188 (Div. 2) A. Even Odds

//#include<stdio.h>
//#include<iostream>
//#include<algorithm>
//#include<vector>
//#include<cstring>
//#include<cmath>
//#include<map>
#include<bits/stdc++.h>
using namespace std;

#define fast ios_base::sync_with_stdio(false)
#define outs(x) cout << x << " "
#define outn(x) cout << x << "\n"
#define sf scanf
#define pf printf

typedef long long LL;

int main()
{
    //fast;
    LL n, k;
    while(~sf("%I64d %I64d", &n , &k))
    {
        LL lim = 0;

        lim = n % 2 == 0 ? n / 2 : (n / 2) + 1;

        if(k > lim)
        {
            // even
            pf("%I64d\n", 2 * (k - lim)) ;
        }

        else
        {
            // odd
            pf ("%I64d\n" , 2 * (k - 1) + 1);
        }
    }

    return 0;
}

Comments

Popular posts from this blog

SPOJ-CMG - Collecting Mango

LightOJ 1009 - Back to Underworld

LeetCode Palindrome Number