Back to problems Sign in to unlock
Codeforces
Easy
Math
Arrays
Even Odds
Find the -th number in a sequence formed by listing all odd numbers up to first, then all even numbers up to .
Acceptance 0%
Also Available On
Other platform versions and source mappings for the same problem.
Problem Statement
Problem
You are given two integers and . Consider the sequence of numbers from $1n$ arranged in this order:
- All odd numbers in increasing order
- All even numbers in increasing order
Your task is to output the -th number in this sequence.
For example, when , the sequence is:
1 3 5 7 9 2 4 6 8 10
and the 7-th element is 4.
Goal
Return the value at position without constructing the entire sequence if possible.
Input Format
- A single line contains two integers and .
- .
Output Format
- Print one integer: the -th element of the described ordering.
Constraints
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.
Guided hints
Editorial and discussion links
Concept map and variants
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.