Math Fundamentals18 sections · 814 units
Open in Course

Ugly Number - Algorithm

(Divide and check remainder)

1.1. If n ≤ 0, return false.

2.2. While n is divisible by 2, divide n by 2.

3.3. While n is divisible by 3, divide n by 3.

4.4. While n is divisible by 5, divide n by 5.

5.5. If n == 1, return true. Otherwise, return false.