fun main() { val distance = readLine()!!.trim().toLong() var result = distance fun sumDistance(step: Int, d: Long): Long { var sum = 0L var dist = d repeat(step) { sum += dist dist /= 2 } return sum } for (step in 2 .. 60) { var min = 0L var max = distance while (min < max) { val mid = (min + max) / 2 val sum = sumDistance(step, mid) if (sum < distance) { min = mid + 1 }else { max = mid } } if (sumDistance(step, max) == distance) { result = minOf(result, max) } } println(result) }