(easy)LeetCode 263.Ugly Number
2015-08-19 16:54
411 查看
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
Credits:
Special thanks to @jianchao.li.fighter for adding this problem and creating all test cases.
代码如下:
运行结果:
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.
代码如下:
public class Solution { public boolean isUgly(int num) { if(num<=0) return false; if(num==1) return true; while(num%2==0) num/=2; while(num%3==0) num/=3; while(num%5==0) num/=5; return num==1; } }
运行结果:
![](http://images0.cnblogs.com/blog2015/789884/201508/191653190509574.png)
相关文章推荐
- MFC常用控件使用方法
- 我们应当怎样做需求分析
- spring Quartz多个定时任务的配置
- ckeditor批量上传图片(下)
- Maven常用库连接
- 在Xcode中玩转Git
- 第一个iOSAPP上架经历
- 解决Xcode6项目中旧项目不全屏问题
- ViewPager点击每一项设置的监听
- 桌面支持--outlook默认中文语言设置
- 【网络流24题之餐巾计划】xoj 1247
- LightOJ - 1422 Halloween Costumes 区间DP
- 值得推荐的C/C++框架和库
- UE3 材质函数
- lemon OA 下阶段工作安排
- 判断一个图中有无环路的存在
- Java Web用Freemarker生成带图片的Word文档
- PSR规范
- android binder
- Android学习要点