[leetcode oj 263]Ugly Number
2016-01-11 16:09
218 查看
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) return isUgly(num / 2); if(num % 3 == 0) return isUgly(num / 3); if(num % 5 == 0) return isUgly(num / 5); return false; } };
相关文章推荐
- Arduino - 休眠模式
- Leetcode 13 - Roman to Integer
- qt&gdal
- 【安装】sublime+emmet
- java如何创建xml文档
- 备忘录模式 c#
- MFC学习(20)MFC打开/保存文件对话框——CFileDialog之一
- opencv cannot open file 'opencv_calib3d249d'
- Java中文编码方法
- Android中setLayoutParams要用父控件的LayoutParams
- 递归回溯
- 渐变色
- 用 Quartz 进行作业调度
- Hibernate4 clob字段存取
- 如何高效检查一个数组中是否包含某个值?
- UICollectionView简单使用
- HDU 1062 Text Reverse【栈 翻转操作】
- CentOS 6 yum安装vsftpd
- C++ API函数 下载文件并放在指定的路径
- LVS/NAT 配置