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 ...
随机推荐
- Git 笔记 - section 1
1. 创建版本库 创建目录 git init git add <file> git commit -m "本次提交内容的说明" 2. 查看状态 git status g ...
- java面试需要准备什么呢?c++可以看看
作者:Mingche Su链接:https://zhuanlan.zhihu.com/p/20545626来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 语言知识点:以 ...
- 基础概念:Oracle数据库
基础概念:Oracle数据库.实例.用户.表空间.表之间的关系 数据库:Oracle数据库是数据的物理存储.这就包括(数据文件ORA或者DBF.控制文件.联机日志.参数文件).其实Oracle数据库的 ...
- CodeForces839B[思维] Codeforces Round #428 (Div. 2)
#include <bits/stdc++.h> using namespace std; int n, k; ; ], cnt[]; void solve() { int t; cnt[ ...
- ZOJ 3874 Permutation Graph ——分治 NTT
发现每一块一定是按照一定的顺序的. 然后与标号无关,并且相同大小的对答案的影响相同. 然后列出递推式,上NTT+分治就可以了. 然后就可以与输入同阶处理答案了. #include <map> ...
- 在npm当中发布自己的包的方法
首先需要一个注册一个npm账号,注意,必须验证邮箱,不然是无法发布包的!下面是当时的报错 接着在你需要发布的包的文件夹下面打开你的cmd或者其他的命令行输入工具 输入 npm init 初始化你的 ...
- git常见操作总结
git config --global user.name "liyang"git config --global user.email "liyangslj@126.c ...
- query带进度上传插件Uploadify(ASP.NET版本)使用
原文发布时间为:2010-05-13 -- 来源于本人的百度文章 [由搬家工具导入] 本文将带给大家很帅的jquery上传插件,ASP.NET版本的哦,这个插件是Uploadify实现的效果非常不错, ...
- 剖析CPU温度监控技术【转】
转自:http://blog.csdn.net/hunanchenxingyu/article/details/46476545 迄今为止还没有一种cpu散热系统能保证永不失效.失去了散热系统保护伞的 ...
- python 条件判断 if
条件判断 if 格式-1 if 判断条件: 执行语句... num = 10 if num == 4: print("num 等于4") 执行: C:\Python27\pytho ...