# -*- coding: utf-8 -*- import sys import math import copy def main(): text = sys.stdin.readline() goal = int(text) #ゴール start = 1 #初期値 path_list = [start] q = Que() q.addQ(path_list) #経路探索処理→幅優先探索、ゴールに到達した時点で終了 while not q.isEmpty(): path_list = q.popQ() next_position_list = nextGoto(path_list[-1]) for p in next_position_list: if p < 1 or p > goal: continue elif p in path_list: continue elif p == goal: path_list.append(p) #print(path_list,len(path_list)-1) print(len(path_list)-1) return else: buf_list = copy.deepcopy(path_list) buf_list.append(p) q.addQ(buf_list) print(-1) return class Que(): q_list = [] def addQ(self,arg_pathlist): self.q_list.append(arg_pathlist) return def popQ(self): return self.q_list.pop(0) def isEmpty(self): if len(self.q_list) <= 0 : flag = True else: flag = False return flag #行先返答関数 def nextGoto(arg_position): binary_text = bin(arg_position) steps = len(binary_text.replace("0b","").replace("0","")) goto = [arg_position + steps, arg_position - steps] return goto if __name__ == "__main__": main()