> For the complete documentation index, see [llms.txt](https://junnie.gitbook.io/nine-chapter/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://junnie.gitbook.io/nine-chapter/8.data-structure/517ugly-number.md).

# 517.Ugly Number

## 1.Description(Easy)

Write a program to check whether a given number is an`ugly`number\`.

`Ugly numbers`are positive numbers whose prime factors only include`2`,`3`,`5`. For example,`6`,`8`are ugly while`14`is not ugly since it includes another prime factor`7`.

### Notice

Note that`1`is typically treated as an ugly number.

**Example**

Given num =`8`return`true`\
Given num =`14`return`false`

[**Tags**](https://www.lintcode.com/en/problem/ugly-number/#tags)

[Mathematics](https://www.lintcode.com/tag/mathematics/)

## 2.Code

```
public boolean isUgly(int num) {
        if(num==1){
            return true;
        }
        if(num<=0){
            return false;
        }

        while(num%2==0){
            num=num/2;
        }
        while(num%3==0){
            num=num/3;
        }
        while(num%5==0){
            num=num/5;
        }

        return (num==1);
    }
```
