lintcode python代码 517丑数

来源:互联网 发布:linux重启 编辑:程序博客网 时间:2024/06/03 20:18

只包含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