[leetcode] Ugly Number
2015-08-20 13:36
155 查看
from : https://leetcode.com/problems/ugly-number/
Write a program to check whether a given number is an ugly number.
Ugly numbers are positive numbers whose prime factors only include
For example,
not ugly since it includes another prime factor
Note that
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, 8are ugly while
14is
not ugly since it includes another prime factor
7.
Note that
1is typically treated as an ugly number.
class Solution { public: bool isUgly(int num) { if(1 >= num) return 1 == num; while(num >= 2 && 0 == (num&1)) num >>= 1; while(num >= 3 && 0 == num%3) num /= 3; while(num >= 5 && 0 == num%5) num /= 5; return 1 == num; } };
相关文章推荐
- CSS样式优先级机制
- 2015盘点最佳5笔小投资引援:骑士得枪勇士收肉盾
- sql server 数据库备份还原
- MongoDB : couldn’t open /data/db/yourdb.ns errno:13 Permission denied
- 【JavaScript】DOM结构介绍和方法预览
- Python:Bubble 排序算法
- iOS申请真机调试证书-图文详解
- Ubuntu 下面安装gtk+-2.0
- [leetcode] 142.Linked List Cycle II
- synchronized与static synchronized 差异
- 正则表达式相关(group用法)
- WSDL教程
- HDU-4786 Fibonacci Tree(最小生成树[Kruskal])
- Myeclipse导出war包
- web service(SOAP)与HTTP接口的区别
- C#线程同步自动重置事件——AutoResetEvent
- javascript form 第22节
- android中在代码中创建应用的快捷图标
- 【JavaScript】javaScript基础知识回顾
- POJ3292——Semi-prime H-numbers