# 263.Ugly Numbers

**263.Ugly Numbers**

难度:Easy

> 编写一个程序判断给定的数是否为丑数。

丑数就是只包含质因数 2, 3, 5 的正整数。

```
示例 1:

输入: 6
输出: true
解释: 6 = 2 × 3
示例 2:

输入: 8
输出: true
解释: 8 = 2 × 2 × 2
示例 3:

输入: 14
输出: false 
解释: 14 不是丑数，因为它包含了另外一个质因数 7。
说明：

1 是丑数。
输入不会超过 32 位有符号整数的范围: [−231,  231 − 1]。
```

能整除2 3 5的话，分别整除至不能整除，看看最后是否等于1即可。

```
class Solution {
public:
    bool isUgly(int num) {
        if(num==0) return false;
        while((num & 1) ==0)
            num>>=1;
        while(num%3==0)
            num/=3;
        while(num%5==0)
            num/=5;
        return num==1;
    }
};
```

> 执行用时 :4 ms, 在所有 C++ 提交中击败了90.96%的用户\
> 内存消耗 :8 MB, 在所有 C++ 提交中击败了60.22%的用户


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dfine.gitbook.io/leetcode/263.ugly_numbers.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
