263. Ugly Number
2016-07-03 10:29
267 查看
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.
Subscribe to see which companies asked this question
代码:
class Solution {
public:
bool isUgly(int num) {
while(num>=2)
{
if(num%2==0) num=num/2;
else if(num%3==0) num=num/3;
else if(num%5==0) num=num/5;
else return false;
}
return num==1;
}
};
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.
Subscribe to see which companies asked this question
代码:
class Solution {
public:
bool isUgly(int num) {
while(num>=2)
{
if(num%2==0) num=num/2;
else if(num%3==0) num=num/3;
else if(num%5==0) num=num/5;
else return false;
}
return num==1;
}
};
相关文章推荐
- .NET Core 1.0发布:微软开源跨平台大布局序幕
- EditText输入事件截获与监听
- java基础之一---java Application初步
- leetCode_Different Ways to Add Parentheses
- 软件大全下载整理(更新中)
- Java内存机制
- web
- SublimeText实用快捷键
- map按value排序, oh my god
- 进入oracle的SQL*PLUS界面
- MongoDB用户创建
- Spark在美团的实践
- 基于MATLAB的高等数学 方向导数
- Html/Css(新手入门第三篇)
- 西门子 PLC S7-200的整数转换为ASCII码指令
- Android客户端集成支付宝快捷支付
- http协议
- 让UIWebview拥有超强的图片处理能力
- 基于MATLAB的高等数学 多元函数求导
- 【CDP-云设计模式】第2章,1.快照模式(Snapshot Pattern)