LeetCode 263----Ugly Number
2015-09-09 17:03
417 查看
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
只能被2、3、5整除的数,不断除2、3、5后,余数为1,余数为其它时,则不是-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.
只能被2、3、5整除的数,不断除2、3、5后,余数为1,余数为其它时,则不是-Ugly Number
class Solution { public: bool isUgly(int num) { int x=num; if(x<=0) return false; while(x>=2) { if(x%2==0) x=x/2; else if(x%3==0) x=x/3; else if(x%5==0) x=x/5; else return false; } if(x==1) return true; } };
相关文章推荐
- JFreeChart创建曲线图
- 多线程学习案例
- jdk配置及maven配置
- 带薪假
- c++获取系统时间(引用别人的博文)
- 【MVC2】发布到IIS7.5上后Session为null
- 友元类 运算符重载 new结构体数组
- Windows 8.1 下 XAMPP 的 Apache 服务器无法启动的解决
- rtp 报头的大小端 可查看jrtplib 中的定义
- Error:Execution failed for task ':app:packageDebug'.
- php代码优化
- poj 1426 Find The Multiple ( dfs )
- OK6410利用NandFlash烧写代码的方法
- Windows Server 2012 配置 IIS 教程
- 纯洁CSS实现下拉菜单和下拉容器(纯洁CSS导航栏和导航下拉容器)
- 阿里巴巴Java招聘
- HTTP常见状态码 200 301 302 404 500
- hdu5371 manacher + 线段树
- int *(*a[5])(int, char*)
- linux 打补丁