标签:ogr hat positive nbsp other color als actor style
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
.
Note that 1
is typically treated as an ugly number.
1 public class Solution { 2 public bool IsUgly(int num) { 3 if (num < 1) return false; 4 5 while (num > 1) 6 { 7 if (num % 2 == 0) 8 { 9 num /= 2; 10 } 11 else if (num % 3 == 0) 12 { 13 num /= 3; 14 } 15 else if (num % 5 == 0) 16 { 17 num /= 5; 18 } 19 else 20 { 21 return false; 22 } 23 } 24 25 return true; 26 } 27 }
标签:ogr hat positive nbsp other color als actor style
原文地址:http://www.cnblogs.com/liangmou/p/7992057.html