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 ...
随机推荐
- Dynamics CRM 插件注册时报Assembly must be registered in isolation的解决方法
在插件注册的时候经常会遇到"Assembly must be registered in isolation"的问题导致无法注册,之前经常会被同事或者朋友问到这个问题,遇到这个问题 ...
- 开源控件ViewPagerIndicator的使用
此文转载自http://www.jianshu.com/p/a2263ee3e7c3 前几天学习了ViewPager作为引导页和Tab的使用方法.后来也有根据不同的使用情况改用Fragment作为Ta ...
- EBS库存(INV)模块常用表
select * from org_organization_definitions库存组织 select * from mtl_parameters组织参数 select * from mtl ...
- FORM中读取图片
1.创建ITEM 重要属性如下 item属性:图像 大小样式:调整 数据库项:否 2.读取触发器 在block级别,创建trigger READ_IMAGE_FILE('D:\'||:XX_EMOLY ...
- 1086. Tree Traversals Again (25)
题目如下: An inorder binary tree traversal can be implemented in a non-recursive way with a stack. For e ...
- UNIX环境高级编程——Linux终端设备详解
终端是一种字符型设备,它有多种类型,通常使用tty来简称各种类型的终端设备.tty是Teletype的缩写.Teletype是最早出现的一种终端设备,很象电传打字机(或者说就是),是由Teletype ...
- RecyclerView下拉刷新上拉加载(二)
listview下拉刷新上拉加载扩展(一) http://blog.csdn.net/baiyuliang2013/article/details/50252561 listview下拉刷新上拉加载扩 ...
- (NO.00005)iOS实现炸弹人游戏(五):游戏数据的初始化(二)
大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 如果觉得写的不好请告诉我,如果觉得不错请多多支持点赞.谢谢! hopy ;) 我们现在来依次看一下上篇中提到的各个方法,首先介绍的是updat ...
- Andriod Studio科普篇——3.关于gradle插件的常见问题
1.andriod gradle插件版本过低. 出错位置: dependencies{ classpath 'com.android.tools.build:gradle:0.10.2' } 提示信息 ...
- 【IOS 开发】Object - C 数组使用详解
. 一. 一维数组 1. 一维数组定义 (1) 数组定义 数组定义格式 : type arrayName[len]; -- 默认初始化 : 注意 数组定以后, 如果是 int 数组默认初始化为 0, ...