Ugly Number

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.

30:00

Ugly Number
easy
Free written solution
Topics
Companies

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.

Example 1:
Input: {"n":6}
Output: true
Constraints:
  • −231≤n≤231−1-2^{31} \leq n \leq 2^{31} - 1

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"n":6}

n = 6. Ugly means positive, with no prime factor other than 2, 3 and 5.

what is left of n

6

factors peeled off

÷2

20

÷3

30

÷5

50

factorization so far

6 = 20 × 30 × 50 × 6
Variables
VariableValue
n6
DepthFunction Call
Stack empty
0/12