百练 / 2019计算机学科夏令营上机考试 C:Hopscotch
# 百练 / 2019计算机学科夏令营上机考试 C:Hopscotch
# http://bailian.openjudge.cn/xly2019/C/
# Author:NitrogenousFish
# github:https://github.com/NITROGENousFish/
class Node:
def __init__(self,val,path):
self.path = path
self.val = val
def main():
num_list = []
while(1):
input_thing = list(map(int,input().split()))
if input_thing[0] == 0 and input_thing[1] == 0:
break
else:
num_list.append(input_thing)
for number_list in num_list:
start = number_list[0]
end = number_list[1]
queue = []
rootnode = Node(start,"")
queue.append(rootnode)
while len(queue):
currentnode = queue.pop(0)
leftnode = Node(currentnode.val*3,currentnode.path+"H")
queue.append(leftnode)
if currentnode.val//2!=0:
rightnode = Node(currentnode.val//2,currentnode.path+"O")
queue.append(rightnode)
if currentnode.val == end:
print(len(currentnode.path))
print(currentnode.path)
return
if __name__ == "__main__":
main()