30:00
An ugly number is a positive integer whose only prime factors are 2, 3 and 5. Given an integer n, return true if n is an ugly number.
−231≤n≤231−1-2^{31} \leq n \leq 2^{31} - 1−231≤n≤231−1
Run code to see results.
n = 6. Ugly means positive, with no prime factor other than 2, 3 and 5.
what is left of n
factors peeled off
÷2
20
÷3
30
÷5
50
factorization so far
Decide whether a given integer is positive and has no prime factors other than 2, 3 and 5. Divide those three primes out as many times as they go in, and the number is ugly exactly when 1 is left.