lintcode python代码 517丑数

只包含2 3 5质数的数是丑数
思路:丑数的质数因子只有2,3,5 被这些质因子整除后一定为1。


class Solution:
    # @param {int} num an integer
    # @return {boolean} true if num is an ugly number or false
    def isUgly(self, num):
        # Write your code her
        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
        if num == 1:
            return True
        else:
            return False

你可能感兴趣的:(Lintcode)