The list initially contains a single integer 1. In each round, you remove the smallest element x from the list, and add the values 2x and 3x to the list. What is the smallest value on the list after n rounds? You may assume that n is at most 10^5.
For example when n=5, the list changes as follows:
[1] \rightarrow [2,3] \rightarrow [3,4,6] \rightarrow [4,6,6,9] \rightarrow [6,6,9,8,12] \rightarrow [6,9,8,12,12,18]
Here the smallest value at the end is 6.
In a file twothree.py
, implement a function smallest
that returns the smallest value.
def smallest(n): # TODO if __name__ == "__main__": print(smallest(1)) # 2 print(smallest(5)) # 6 print(smallest(123)) # 288 print(smallest(55555)) # 663552