Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Ugly Numbers by kt1729
from functools import cache
from itertools import combinations_with_replacement, permutations
@cache
def ugly_number(n: int) -> int:
num = set()
i012 = list(permutations(range(3),3))
if n<10: coef = 0.67
elif n<=240: coef = 0.61
elif n<380: coef = 0.5
else: coef = [0.49,0.48][n>600]
for p in combinations_with_replacement(range(0,round(n**coef)),3):
for i in i012:
num.add(2**p[i[0]]*3**p[i[1]]*5**p[i[2]])
un = sorted(list(num))
return un[n-1]
Feb. 3, 2023
Comments: