Leetcode_263_Ugly Number
本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/49431329
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, 8 are ugly while 14 is not ugly since it includes another prime factor 7.
Note that 1 is typically treated as an ugly number.
思路:
(1)该题题意为给定一个数,判断该数是否为“丑数”。
(2)这道题很基础。丑数是因子只含有2、3、5的数。所以只需对这三个数循环取余判断即可。这里不再累赘。
(3)详情见下方代码。希望本文对你有所帮助。
public class Ugly_Number {
public static void main(String[] args) {
for (int i = 0; i < 100; i++) {
System.err.println(i + "==" + isUgly(i));
}
}
// 2 3 5
public static boolean isUgly(int num) {
if (num == 1)
return true;
while (num >= 2 && num % 2 == 0) {
num = num / 2;
}
while (num >= 3 && num % 3 == 0) {
num = num / 3;
}
while (num >= 5 && num % 5 == 0) {
num = num / 5;
}
return num == 1 ? true : false;
}
}
Leetcode_263_Ugly Number的更多相关文章
- JavaScript Math和Number对象
目录 1. Math 对象:数学对象,提供对数据的数学计算.如:获取绝对值.向上取整等.无构造函数,无法被初始化,只提供静态属性和方法. 2. Number 对象 :Js中提供数字的对象.包含整数.浮 ...
- Harmonic Number(调和级数+欧拉常数)
题意:求f(n)=1/1+1/2+1/3+1/4-1/n (1 ≤ n ≤ 108).,精确到10-8 (原题在文末) 知识点: 调和级数(即f(n))至今没有一个完全正确的公式, ...
- Java 特定规则排序-LeetCode 179 Largest Number
Given a list of non negative integers, arrange them such that they form the largest number. For exam ...
- Eclipse "Unable to install breakpoint due to missing line number attributes..."
Eclipse 无法找到 该 断点,原因是编译时,字节码改变了,导致eclipse无法读取对应的行了 1.ANT编译的class Eclipse不认,因为eclipse也会编译class.怎么让它们统 ...
- 移除HTML5 input在type="number"时的上下小箭头
/*移除HTML5 input在type="number"时的上下小箭头*/ input::-webkit-outer-spin-button, input::-webkit-in ...
- iOS---The maximum number of apps for free development profiles has been reached.
真机调试免费App ID出现的问题The maximum number of apps for free development profiles has been reached.免费应用程序调试最 ...
- 有理数的稠密性(The rational points are dense on the number axis.)
每一个实数都能用有理数去逼近到任意精确的程度,这就是有理数的稠密性.The rational points are dense on the number axis.
- [LeetCode] Minimum Number of Arrows to Burst Balloons 最少数量的箭引爆气球
There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided ...
- [LeetCode] Number of Boomerangs 回旋镖的数量
Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of po ...
随机推荐
- nginx中configure脚本支持的常用选项,拍摄自《Nginx高性能Web服务器详解》
- SQLite 数据类型(http://www.w3cschool.cc/sqlite/sqlite-data-types.html)
SQLite 数据类型 SQLite 数据类型是一个用来指定任何对象的数据类型的属性.SQLite 中的每一列,每个变量和表达式都有相关的数据类型. 您可以在创建表的同时使用这些数据类型.SQLite ...
- JSP1.x 自定义标签
Tag接口 任何一个标签都对应着一个java类,该类必须实现Tag接口,JSP遇到一个标签后后,将通过一个tld文件查找该标签的实现类,并运行该类的相关方法 import javax.servlet. ...
- Android简易实战教程--第二十五话《网络图片查看器》
访问网络已经有了很成熟的框架.这一篇只是介绍一下HttpURLConnection的简单用法,以及里面的"注意点".这一篇可以复习或者学习HttpURLConnection.han ...
- Android开发学习之路--NDK、JNI之初体验
好久没有更新博客了,最近一直在看一个仿微信项目,然后看源码并自己实现下,相信经过这个项目可以让自己了解一个项目中的代码以及种种需要注意的事项.不知不觉中博客已经快要40w访问量,而且排名也即将突破30 ...
- debian 安装jdk
JDK下载http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-javase6- ...
- 未完成的IT路停在回车键---2014年末总结篇
时间都去哪儿了? 一晃而过,越来越能体会到这个词的真实感.特别是过了二十岁,这种感觉越来越深刻,越来越强烈,犹如小编做公交车的时候一直向后排排倒的香樟树,还记得有首歌叫时间都哪儿了,而 ...
- CUDA程序的调试总结【不定时更新】
1 )CUDA的程序,经常犯,但是很难发现的一个错误就是同步问题. 描述下实例 for (k = 0; k < N; k+=BS) { sda[tx] = gda[tx+index]; __sy ...
- 【翻译】如何创建Ext JS暗黑主题之二
原文:How to Create a Dark Ext JS Theme– Part 2 我已经展示了如何去开发一个精致的暗黑主题,看起来就像Spotify.在本文的第一部分,了解了Fashion.S ...
- 在IFrame中查找IFRAME中的元素的方式
下面是内部iframe找外部mainFrame的情况 var websiteSearchButton = window.parent.parent.document.getElementById(' ...