Ugly Number
2017-02-13 10:24
381 查看
Write a program to check whether a given number is an ugly number.
Ugly numbers are positive numbers whose prime factors only include
Note that
Ugly numbers are positive numbers whose prime factors only include
2, 3, 5. For example,
6, 8are ugly while
14is not ugly since it includes another prime factor
7.
Note that
1is typically treated as an ugly number
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 if num == 1: return True else: return False """ if num <= 0: return False for x in [2,3,5]: while num%x == 0: num /= x return num == 1
相关文章推荐
- [讨论] 2015-8-13日 主题:关于指针和堆栈
- 8086汇编3:负数的表示法-补码
- Android 获取当前的时间。年月日,时分秒
- android自定义View之margin和padding的处理
- Class.forName()的作用
- HttpClient连接超时及读取超时
- 如何快速学习新的知识
- 如何在FineReport中解析数据库内XML文件
- Git使用说明--常用命令
- App 冷启动:给 Android 的 Activity 添加一个背景
- android智能指针的原理
- 关于JDBC连接MYSQL的操作问题
- Maven pom.xml 配置笔记
- Proguard中optimize设置不当引发SimException
- 完美解决android软键盘监听
- MongoDB 基础入门
- 修改Activity的继承类导致程序闪退
- [ Eclipse ] [ Problem ] Eclipse 無法開啟問題
- 【255】◀▶IEW-Unit20
- 非技术相关的面试技巧(文章内容来自他人博客)