'''
题目:我们把只包含因子2、3和5的数称作丑数。求按从小到大的顺序的第1500个丑数。1为第一个丑数。
'''
def get_ugly_number(count):
if count <= 0:
return 0;
ugly_number_list = [1]
multiply2 = 0
multiply3 = 0
multiply5 = 0
while len(ugly_number_list) < count:
m = min((ugly_number_list[multiply2] * 2, ugly_number_list[multiply3] * 3, ugly_number_list[multiply5] * 5))
ugly_number_list.append(m)
while ugly_number_list[multiply2] * 2 <= ugly_number_list[-1]:
multiply2 += 1
while ugly_number_list[multiply3] * 3 <= ugly_number_list[-1]:
multiply3 += 1
while ugly_number_list[multiply5] * 5 <= ugly_number_list[-1]:
multiply5 += 1
print ugly_number_list
return ugly_number_list[-1]
if __name__ == '__main__':
print get_ugly_number(1500)
网友评论