leetcode(12),Ugly Number(python)

原创 2016年06月02日 00:09:37

question:

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.

判断一个数是否为丑数,就是看这个数,能否被【2,3,5】不断整除。

默认1为/丑数。

例如: 8/2=4  4/2=2   2/2=1

即8为丑数

代码如下:

    def isUgly(num):
        if num <= 0:
            return False
        for x in [2, 3, 5]:
            while num % x == 0:
                num /= x
        return num == 1           #不是1则为False


版权声明:本文为博主原创文章,转载请私信联系。

相关文章推荐

【LEETCODE】313-Super Ugly Number [Python]

yield,map,heapq.merge,next

LeetCode Ugly Number i,ii详解

// Date : 2016.07.25 // Author : yqtao // https://github.com/yqtaowhu/**************************...

[Leetcode] Ugly Number II

题目描述: Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose pr...

Leetcode Super Ugly Number

题目写一个程序查找第n个super ugly number. 一个super ugly number 是所有质数由给定列表中的质数构成的正整数。比如,对给定的素数列表:primes = [2, 7,...

LeetCode-313. Super Ugly Number (JAVA)超级丑数

LeetCode-313. Super Ugly Number (JAVA)超级丑数

LeetCode-263.264. Ugly Number II (JAVA)丑数

LeetCode-263.264. Ugly Number II (JAVA)丑数

20170307-leetcode-263-Ugly Number

1.DescriptionWrite a program to check whether a given number is an ugly number.Ugly numbers are posi...

leetcode Ugly Number II

Problem Write a program to find the n-th ugly number. Ugly numbers are positive numbers whos...

Leetcode 264(Ugly Number II)

QuestionWrite a program to find the nthn^{th} ugly number.Ugly numbers are positive numbers whose pr...

<LeetCode OJ> 26 / 264 / 313 Ugly Number (I / II / III)

263. Ugly Number My Submissions Question Total Accepted: 33755 Total Submissions: 96873 Difficul...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)