statement: The title is from the "point of the sword". Algorithm principle please find your own book, not nonsense. Directly on the Python version code.
Title: The 1500th Ugly number in order from small to large. We call the numbers that contain only the factors 2, 3, and 5 as ugly (Ugly number)
1 #Calculate the 1500th number of ugly2 #1,2,3,4,53 Importdatetime4 5StartTime =Datetime.datetime.now ()6 7Uglynumberlist = [1]8Indexlist = [[0,2], [0,3], [0,5]]9 Ten whileLen (uglynumberlist) <= 1500: Onevar = min (uglynumberlist[indexlist[0][0]]*2, uglynumberlist[indexlist[1][0]]*3, uglynumberlist[indexlist[2][0]]*5) A forIinchRange (0, 3): - ifUGLYNUMBERLIST[INDEXLIST[I][0]]*INDEXLIST[I][1] = =var: -Indexlist[i][0] + = 1 the Else: - Uglynumberlist.append (Var) - Else: -Deltatime = Datetime.datetime.now ()-StartTime + Print("The ugly number is {}\ntime consuming is {} MS". Format (Uglynumberlist[-1], deltatime.total_seconds () *1000))
Python Programming Algorithm Practice _001