# Time: O(logn) = O(1)
# Space: O(1)

class Solution:
    def isUgly(self, num):
        if not num:
            return False

        while num % 2 == 0:
            num = num / 2

        while num % 3 == 0:
            num = num / 3

        while num % 5 == 0:
            num = num / 5

        return num == 1:
        #if num == 1:
        #    return True
        #else:
        #    return False


if __name__ == "__main__":
    num = 14
    s = Solution()
    print(s.isUgly(num))
# Time: O(logn) = O(1)
# Space: O(1)

class Solution:
    def isUgly(self, num):
        if not num:
            return False

        while num % 2 == 0:
            num = num / 2

        while num % 3 == 0:
            num = num / 3

        while num % 5 == 0:
            num = num / 5

        return num == 1:
        #if num == 1:
        #    return True
        #else:
        #    return False


if __name__ == "__main__":
    num = 14
    s = Solution()
    print(s.isUgly(num))
# Time: O(logn) = O(1) # Space: O(1) #if num == 1: #    return True #else: #    return False