# C#LeetCode刷题之#263-丑数（Ugly Number）

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

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.

Input: 6

Output: true

Explanation: 6 = 2 × 3

Input: 8

Output: true

Explanation: 8 = 2 × 2 × 2

Input: 14

Output: false

Explanation: 14 is not ugly since it includes another prime factor 7.

Note:

1. 1 is typically treated as an ugly number.
2. Input is within the 32-bit signed integer range: [−231,  231 − 1].

```public class Program {

public static void Main(string[] args) {
var n = 60;
var res = IsUgly(n);
Console.WriteLine(res);

}

private static bool IsUgly(int num) {
var uglyList = new int[] { 2, 3, 5 };
foreach(var ugly in uglyList) {
while(num % ugly == 0 && (num /= ugly) > 0) { }
}
return num == 1;
}

}```

`True`