TopcoderARCHIVE
Archive/Problems/AlternateOddEven
TCO · Problem 17010

AlternateOddEven

Problem statement, definition, constraints, and public examples.

Problem Statement

Consider all the positive integers with the property that their digits alternate between being odd and even. The sequence of these numbers begins as follows:

1, 2, ..., 9, 10, 12, 14, 16, 18, 21, 23, 25, 27, 29, 30, 32, ..., 96, 98, 101, 103, 105, 107, 109, 121, 123, ..., 187, 189, 210, 212, ...


Given K, which is the K-th number in this sequence?

Definition

Class:
AlternateOddEven
Method:
kth
Parameters:
long
Returns:
long
Method signature:
long kth(long K)
(be sure your method is public)

Notes

  • The answer for each valid test case is guaranteed to fit into a signed 64-bit integer.

Constraints

  • K will be between 1 and 10^11, inclusive.

Examples

  1. 9
    Returns: 9
    The first nine numbers in our sequence (positions 1 to 9) are the nine one-digit positive integers.
  2. 15
    Returns: 21
    The next six numbers (in positions 10 to 15) are 10, 12, 14, 16, 18, 21.
  3. 62
    Returns: 125
  4. 100
    Returns: 290
← All problems