Sort Integers by the Power Value (Collatz)

Problem

For each integer x in [lo, hi], define its "power" as the number of Collatz steps to reach 1 (if x is even → x/2, if odd → 3x+1). Sort the integers by ascending power, breaking ties by ascending value, and return the k-th integer (1-indexed) in that order.

Input / Output

  • Input: integers lo, hi, k.
  • Output: the k-th integer of [lo, hi] under the (power, value) ordering.

Constraints

  • 1 ≤ lo ≤ hi ≤ 1000
  • 1 ≤ k ≤ hi − lo + 1
  • Powers can be large for some values even though the range is small.

Example

lo=12, hi=15, k=2 -> 13

Powers: 12→9, 13→9, 14→17, 15→17; sorted by (power, value) = [12,13,14,15]; the 2nd is 13.

added …
LeaderboardSalaryAccount