leetcode 263. Ugly Number
2016-03-14 15:43
344 查看
题目内容
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.
题目分析
判断一个数,它的质因数是不是只有2,3,5,如果是,这个数是一个“丑数”,包含其他质因数,则不是。
所以要对给定的数不断的除2,3,5,直到除的有余数为止,如果除尽则是,否则,不是。、
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.
题目分析
判断一个数,它的质因数是不是只有2,3,5,如果是,这个数是一个“丑数”,包含其他质因数,则不是。
所以要对给定的数不断的除2,3,5,直到除的有余数为止,如果除尽则是,否则,不是。、
public class Solution { public boolean isUgly(int num) { if(num<1) return false; 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; } }
相关文章推荐
- Android开发之播放视频
- FTxxxx系列------变量初始化buf失败
- Perl正则表达式总结_3
- Android开发&HTML5+App
- css3中-moz、-ms、-webkit分别代表的意思
- 关于 overridePendingTransition()使用
- Java编程思想(一):大杂烩
- 配置ssh的双机信任
- 侯捷《深入浅出MFC》中“Hello, MFC”如何改写到VS2012中
- 线程的睡眠与唤醒
- Exchange 2016 混合部署后的测试工作
- 使用UEditor在门户中添加公告
- I2C Tools 学习笔记
- 在Mac中配置Android的环境变量
- 永不执行的代码warning处理
- Android Studio使用butterknife注解框架插件Android Butterknife Zelezny
- Ideas and feature requests: Hot (211 ideas) – GenMyModel Support
- bash之花括号展开(brace expansion)
- 安装操作系统
- 平台功能导航配置