LeetCode OJ 之 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, are ugly while
814 is not ugly since it includes another prime factor 7.
Note that 1 is typically treated as an ugly number.
思路:
參考:http://blog.csdn.net/u012243115/article/details/45222269。
代码:
class Solution {
public:
bool 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;
}
};
LeetCode OJ 之 Ugly Number (丑数)的更多相关文章
- LeetCode OJ:Ugly Number II(丑数II)
Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime factors ...
- LeetCode OJ:Ugly Number(丑数)
Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers ...
- LeetCode OJ 之 Ugly Number II (丑数-二)
题目: Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime fact ...
- Ugly number丑数2,超级丑数
[抄题]: [思维问题]: [一句话思路]:Long.valueOf(2)转换为long型再做 [输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入): [画图 ...
- 263 Ugly Number 丑数
编写程序判断给定的数是否为丑数.丑数就是只包含质因子 2, 3, 5 的正整数.例如, 6, 8 是丑数,而 14 不是,因为它包含了另外一个质因子 7.注意: 1 也可以被当做丑数. 输 ...
- [LeetCode] 313. Super Ugly Number 超级丑陋数
Write a program to find the nth super ugly number. Super ugly numbers are positive numbers whose all ...
- 【Leetcode】264. Ugly Number II ,丑数
原题 Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime facto ...
- [LeetCode]313. Super Ugly Number超级丑数,丑数系列看这一道就行了
丑数系列的题看这一道就可以了 /* 和ugly number2差不多,不过这次的质因子多了,所以用数组来表示质因子的target坐标 target坐标指的是这个质因子此次要乘的前任丑数是谁 */ pu ...
- [LeetCode] Ugly Number 丑陋数
Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers ...
随机推荐
- maven学习(五)——maven命令的组合使用
Maven的命令组合使用 maven的编译,清理,测试,打包,部署命令是可以几个命令同时组合起来使用的,常用的命令组合如下: 1.先清理再编译:"mvn clean compile" ...
- BZOJ 1877:[SDOI2009]晨跑(最小费用最大流)
晨跑DescriptionElaxia最近迷恋上了空手道,他为自己设定了一套健身计划,比如俯卧撑.仰卧起坐等 等,不过到目前为止,他坚持下来的只有晨跑. 现在给出一张学校附近的地图,这张地图中包含N个 ...
- 【bzoj1221】[HNOI2001] 软件开发 费用流
题目描述 某软件公司正在规划一项n天的软件开发计划,根据开发计划第i天需要ni个软件开发人员,为了提高软件开发人员的效率,公司给软件人员提供了很多的服务,其中一项服务就是要为每个开发人员每天提供一块消 ...
- HDU 5884 Sort(二分答案+计算WPL的技巧)
Sort Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...
- [BZOJ2036]聪明的阿卑多
[BZOJ2036]聪明的阿卑多 试题描述 也许你从没听说过阿卑多,但你一定知道他爷爷的爷爷的爷爷,那就是聪明绝顶的阿凡提先生.是的,阿卑多也是个聪明的小孩. 一天,阿卑多骑着他的小毛驴,在小镇上晃悠 ...
- [CQOI2015][bzoj3930] 选数 [杜教筛+莫比乌斯反演]
题面: 传送门 思路: 首先我们把区间缩小到$\left[\lfloor\frac{L-1}{K}\rfloor,\lfloor\frac{R}{K}\rfloor\right]$ 这道题的最特殊的点 ...
- 新blog新帖><
欢迎来到Mychael的无声乐章 今天搬到了博客园,以后就在这个安谧的地方创作啦OvO 把以前的博客搬了过来 以前的分类似乎崩了.... [以前一些LaTex公式可能会崩掉,那就回我原博客看吧Mych ...
- 小M的作物 最大权闭合子图
题目大意 bzoj 3438 两个田\(A,B\) \(n\le 1000\)种作物的种子 第\(i\)个种子,种\(A\)价值\(a[i]\),种\(B\)价值\(b[i]\) 再给出\(m\)个子 ...
- CODEVS【1380】没有上司的舞会
题目描述 Description Ural大学有N个职员,编号为1~N.他们有从属关系,也就是说他们的关系就像一棵以校长为根的树,父结点就是子结点的直接上司.每个职员有一个快乐指数.现在有个周年庆宴会 ...
- js Regex match, exec, test & jquery plugin, visit the official website!
http://plugins.jquery.com/?s=bootstrap 1. /reg/.test(strval) 2."strval".match(/reg/g), a r ...