Ugly Number 寻找丑数 简单题
2015-08-25 14:23
369 查看
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
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.
Credits:
Special thanks to @jianchao.li.fighter for adding this problem and creating all test cases.
class Solution { public: bool isUgly(int num) { if(num==0) return false; while(num%2==0) num=num/2; while(num%3==0) num=num/3; while(num%5==0) num=num/5; if(num==1) return true; else return false; } };
相关文章推荐
- SQL数据库增删改查基本语句
- iOS利用通知(NSNotification)进行传值
- vmware:Cannot open the disk 'XXX' or one of the snapshot disks it depends on.
- HDU 3605 Escape(多重匹配之多对多的匹配)
- iOS 辛格尔顿
- C# WebService动态调用
- SharePreferences 存储复杂类型数据
- cxf自定义返回错误信息
- Unity3D Terrain
- Vmware私有云虚拟机(CentOS 6.5 OS)之根分区扩容
- 博客园CSS代码
- Java调试的变迁:从System.out.println到log4j
- java web 登录后更新JSESSIONID
- ios语法——委托和协议
- HiveServer 与 HiveServer2
- 深入理解Java:SimpleDateFormat安全的时间格式化
- Aptitude Test Practice
- 求斐波那契(Fibonacci)数列通项的七种实现方法
- 优秀博客1
- tableDnD实现table里行的拖拽排序