class Solution:
def GetUglyNumber_Solution(self,index: int) -> int:
if index < 7:
return index
i2,i3,i5 = 0,0,0
res = [1]
for i in range(1,index):
tmp = min([res[i2]*2,res[i3]*3,res[i5]*5])
res.append(tmp)
if tmp == res[i2]*2:
i2 = i2+1
if tmp == res[i3]*3:
i3 = i3+1
if tmp == res[i5]*5:
i5 = i5+1
return res[index-1]
def solution(n:int)-> int:
# your code here
res = []
i = 1
while len(res) < n:
if isUglyNum(i) == True:
res.append(i)
if len(res) == n:
return res[-1]
i += 1
def isUglyNum(n):
while n % 2 == 0:
n = n // 2
while n % 3 == 0:
n = n // 3
while n % 5 == 0:
n = n // 5
if n == 1:
return True
else:
return False
assert solution(7) == 8
assert solution(50) == 243
def solution(n: int) -> int:
num = 1
count = 1
while count <= n:
c = num
while True:
for i in [2, 3, 5]:
if c % i == 0:
c = c // i
break
else:
if c == 1:
count += 1
break
num += 1
return num - 1
assert solution(7) == 8
assert solution(50) == 243
def solution(n)-> int:
#数据范围 0≤x≤2000
num_list=[1]
for i in range(2,2001):
c=i
while i%2==0:
i/=2
while i%3==0:
i/=3
while i%5==0:
i/=5
if i==1:
num_list.append(c)
return num_list[n-1]
def solution(n: int) -> int:
num_list = [2, 3, 5]
s1 = 1
n1 = 1
while n1 <= n:
s = s1
while True:
for i in num_list:
if s % i == 0:
s //= i
break
else:
if s == 1:
n1 += 1
break
s1 += 1
return s1-1
assert solution(7) == 8
assert solution(50) == 243