-
Notifications
You must be signed in to change notification settings - Fork 160
/
ugly-number.md
33 lines (24 loc) · 998 Bytes
/
ugly-number.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<p>Write a program to check whether a given number is an ugly number.</p>
<p>Ugly numbers are <strong>positive numbers</strong> whose prime factors only include <code>2, 3, 5</code>.</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input:</strong> 6
<strong>Output:</strong> true
<strong>Explanation: </strong>6 = 2 × 3</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input:</strong> 8
<strong>Output:</strong> true
<strong>Explanation: </strong>8 = 2 × 2 × 2
</pre>
<p><strong>Example 3:</strong></p>
<pre>
<strong>Input:</strong> 14
<strong>Output:</strong> false
<strong>Explanation: </strong><code>14</code> is not ugly since it includes another prime factor <code>7</code>.
</pre>
<p><strong>Note:</strong></p>
<ol>
<li><code>1</code> is typically treated as an ugly number.</li>
<li>Input is within the 32-bit signed integer range: [−2<sup>31</sup>, 2<sup>31 </sup>− 1].</li>
</ol>