AlternateOddEven
TCO21 Parallel 2B · 2021-04-13 · by misof
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?
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.
9 Returns: 9
The first nine numbers in our sequence (positions 1 to 9) are the nine one-digit positive integers.
15 Returns: 21
The next six numbers (in positions 10 to 15) are 10, 12, 14, 16, 18, 21.
62 Returns: 125
100 Returns: 290
100000000000 Returns: 2107276767676781
Submissions are judged against all 62 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class AlternateOddEven with a public method long long kth(long long K) · 62 test cases · 2 s / 256 MB per case