Determine whether a number is ugly by checking if it can be reduced to 1 using only factors 2, 3, and 5.
A positive integer is called ugly if its prime factors are limited to 2, 3, and 5.
Given an integer n, return true if n is an ugly number, otherwise return false.
An ugly number must be positive.
1 is considered ugly.0 is not ugly.You may repeatedly divide the number by 2, 3, and 5 while possible. If the final value becomes 1, the number is ugly.
n.true if n is an ugly number; otherwise return false.n is an integer.n may be positive, zero, or negative.1 as ugly.2, 3, or 5 are not ugly.Example 1
Input
n = 6
Output
true
Explanation
6 = 2 × 3, and its prime factors are only 2 and 3.
Example 2
Input
n = 14
Output
false
Explanation
14 = 2 × 7, and 7 is not allowed.
Example 3
Input
n = 1
Output
true
Explanation
1 is defined as an ugly number.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.