30:00
An ugly number is a positive integer whose only prime factors are 2, 3 and 5 (1 counts as ugly). Given an integer n, return the nth ugly number.
1≤n≤16901 \leq n \leq 16901≤n≤1690
Run code to see results.
ugly[0] = 1: the smallest ugly number. Every later one is some earlier ugly number times 2, 3 or 5.
three candidate lanes
×2
i2 = 0
1×2
×3
i3 = 0
1×3
×5
i5 = 0
1×5
ugly[] (1 of 10 filled)
0
1
newest ugly number: 1
Ugly numbers are positive integers whose only prime factors are 2, 3 and 5, with 1 counted as the first one. Given n, return the nth ugly number in increasing order.