dsa · easy
Ugly Number
An ugly number is a positive integer whose prime factors are only 2, 3, and/or 5. 1 is ugly. Return whether n is ugly.
Arguments
n— integer to test
Example
n = 6 → true (2×3). n = 14 → false (has a 7). n = 1 → true.
Constraints
-2^31 <= n <= 2^31 - 1 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.
Examples
Example 1
Input: 6 Expected: true
Example 2
Input: 1 Expected: true
Example 3
Input: 14 Expected: false