package Yukicoder /** * Created by hichikawa on 2015/11/12. */ fun main(args: Array) { fun readLineLongArray(): List { val str = readLine() as String val arrStr = str.split(" ") val ret = arrStr.map { it.toLong() } return ret } fun readLineLong(): Long { val str = readLine() as String return str.toLong() } fun readLineInt(): Int { val str = readLine() as String return str.toInt() } fun readLineIntArray() : List { val str = readLine() as String val arrStr = str.split(" ") val ret = arrStr.map { it.toInt() } return ret } fun readLineDoubleArray(): List { val str = readLine() as String val arrStr = str.split(" ") val ret = arrStr.map { it.toDouble() } return ret } fun readLineDouble() : Double { val str = readLine() as String return str.toDouble() } // fun readLineStringArray(): List { // val str = readLine() as String // val arrStr = str.split(" ") // return arrStr // } val goal = readLineInt() var count = 1 var position = 1 var arrFlag = Array(goal, {false}) while (true) { if (position > goal) { println(-1) return } val move = Integer.bitCount(position) if (position + move == goal) { count++ println(count) break } else if (position + move > goal) { position -= move if (arrFlag[position]) { println(-1) return } } else { position += move } arrFlag[position] = true // println(position) count++ } }