(Go语言)263.UglyNumber
好像就是算因数有没有2、3、5以外的因数
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.
package main
import (
"fmt"
)
func isUgly(num int) bool {
if num <= 0 {
return false
}
for {
if num%2 != 0 {
break
}
num /= 2
}
for {
if num%3 != 0 {
break
}
num /= 3
}
for {
if num%5 != 0 {
break
}
num /= 5
}
if num == 1 {
//fmt.Println("true")
return true
} else {
//fmt.Println("false")
return false
}
}
func main() {
fmt.Println(isUgly(6))
fmt.Println(isUgly(8))
fmt.Println(isUgly(14))
fmt.Println(isUgly(1))
}