leetcode---Ugly Number
2016-04-05 17:46
330 查看
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.
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.
class Solution { public: bool isUgly(int num) { if(num <= 0) return false; if(num == 1) return true; if(num % 2 == 0) while(num % 2 == 0) num /= 2; if(num % 3 == 0) while(num % 3 == 0) num /= 3; if(num % 5 == 0) while(num % 5 == 0) num /= 5; return num == 1; } };
相关文章推荐
- Mahout安装
- 大数据离线处理和常用工具
- 字符串如何转变为倒叙
- Android百度地图开发 百度地图得到当前位置
- Ehcache解读
- 自制反汇编逆向分析工具 迭代第四版本
- VS 常用高效 快捷键
- 济南android培训机构应该如何来选择?
- MVC API
- unity, 使导入的材质名与3dmax中一致
- JVM监控与调优
- vim搜索
- 【Linux】Sed简明教程
- linux backtrace追踪错误调用
- 高斯模糊的算法
- How to use AIDL
- Android开发常用工具方法
- Android中Binder的学习
- Sublime Text 输入中文显示方框问号乱码
- Java 集合体系之 Map 源码分析