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 ...
随机推荐
- Selenium - WebDriver: Locating Elements
Selenium provides the following methods to locate elements in a page: find_element_by_id find_elemen ...
- 集训队日常训练20181110 DIV2 题解及AC代码
4375: 孪生素数 Time Limit(Common/Java):1000MS/3000MS Memory Limit:65536KByteTotal Submit: 324 ...
- 抓取js动态生成数据
最近在抓数据,一般的网页数据抓取相对容易一些,今天在抓电视猫的节目单,发现有些数据时抓取不到的,Java端得到的HTML文件里面没有某一段代码,查了很多资料,发现说是js动态生成的数据,无法直接抓取, ...
- 百度地图API 根据地址查询经纬度
html页面.引用上API: <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> ...
- php读写文件要加锁
http://www.bubuko.com/infodetail-241753.html
- mac 常用操作
1. 快速获取文件夹的位置: 打开文本 terminal 程序,将文件拖进去,路径会自己主动打印出来 2. 移动文件夹: 选中目标文件,然后使用 Command+C 复制,然后用 Command +O ...
- Manacher--雾窗寒对遥天暮,暮天遥对寒窗雾
POJ 3974: Palindrome 题意: 最长回文子串的长度... 分析: Manacher板子题... 代码: #include<algorithm> #include<i ...
- 【Educational Codeforces Round 53 (Rated for Div. 2)】
A:https://www.cnblogs.com/myx12345/p/9853775.html B:https://www.cnblogs.com/myx12345/p/9853779.html ...
- Javascript&Html-系统对话框
Javascript&Html-系统对话框 浏览器通常内置三种对话框,他们分别是 alert(),confirm()以及prompt() .这三种对话框的外形跟页面的HTML以及CSS均没有任 ...
- django Modelform 使用
前言: 为什么要用form去验证呢? 我们提交的是form表单,在看前端源码时如果检查到POST URL及我们提交的字段,如果没有验证我们是否可以直接POST数据到URL,后台并没有进行校验,直接处理 ...