Ugly Number
263 Ugly Number I
Check if a number is ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. 1 is usually consider as an ugly number.
264 Ugly number II
Write a program to find the n-th ugly number.
All the ugly numbers are in format 2^a x 3^b x 5^c, ugly numbers are subsequence factor of ugly numbers.
Time O(n^2), Space O(1). Loop increasing number, check if it is a ugly number.
Time O(n), Space O(n). Dynamic programming, Record the subsequence of prime factors and find the smallest.
313 Super ugly number
Write a program to find the nth super ugly number. Super ugly numbers are positive numbers whose all prime factors are in the given prime list primes of size k.
Last updated
Was this helpful?