Codeforces 318A. Even Odds
Solve in C:
#include<stdio.h>
int main()
{
long long int n,k,a,r;
while(scanf("%lld%lld",&n,&k)!=EOF)
{
if(n%2==0)
{
if(k<=n/2)
{
r=2*k-1;
printf("%lld\n",r);
}
else
{
r=2*k-n;
printf("%lld\n",r);
}
}
else if(n%2==1)
{
a=n/2+1;
if(k<=a)
{
r=2*k-1;
printf("%lld\n",r);
}
else
{
r=2*k-(n+1);
printf("%lld\n",r);
}
}
}
}
#include<stdio.h>
int main()
{
long long int n,k,a,r;
while(scanf("%lld%lld",&n,&k)!=EOF)
{
if(n%2==0)
{
if(k<=n/2)
{
r=2*k-1;
printf("%lld\n",r);
}
else
{
r=2*k-n;
printf("%lld\n",r);
}
}
else if(n%2==1)
{
a=n/2+1;
if(k<=a)
{
r=2*k-1;
printf("%lld\n",r);
}
else
{
r=2*k-(n+1);
printf("%lld\n",r);
}
}
}
}
No comments