https://leetcode-cn.com/problems/ugly-number/
丑数是因子只含有质因数2,3,5,的数。
如果要判断一个数是否为丑数,除以这个数的所有为2,3,5的因子。如果最后结果等于1,那么这个数为丑数。
class Solution(object):
def isUgly(self, num):
"""
:type num: int
:rtype: bool
"""
if num<= 0:
return False
while num %2 == 0:
num /= 2
while num %3 == 0:
num /= 3
while num %5 == 0:
num /= 5
return num == 1