【LeetCode】263. Ugly Number 丑数判断
2016-04-27 13:38
337 查看
题目:
Write a program to check whether a given number is an ugly number.
Ugly numbers are positive numbers whose prime factors only include
Note that
理解:
给定一个正整数,判断这个正整数是否为丑数。
丑数的定义为:1为丑数,丑数可以表示为有限个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, 8are ugly while
14is not ugly since it includes another prime factor
7.
Note that
1is typically treated as an ugly number.
理解:
给定一个正整数,判断这个正整数是否为丑数。
丑数的定义为:1为丑数,丑数可以表示为有限个2、 3、 5相乘。
代码:
class Solution { public: bool isUgly(int num) { if(num<=0) return 0; int temp1=num%2; int temp2=num%3; int temp3=num%5; while(temp1==0||temp2==0||temp3==0) { if(temp1==0) num/=2; else if(temp2==0) num/=3; else num/=5; temp1=num%2; temp2=num%3; temp3=num%5; } return num==1; } };
相关文章推荐
- 发消息的基类
- android 调用 su 指令
- Dagger2 注解 初识
- 扩展方法(C#)
- 扩展方法(C#)
- LigerUI用Post\Get\Ajax前后台交互方式的写发
- java IO流操作文章
- WebService 的工作原理
- 常用Linux命令
- 415 Unsupported Media Type
- Create and Use a Custom Formatter in the Apache HBase Shell
- 利用freemarker生成xml
- Java内存机制
- 免费开源网管软件cacti,nagios,zabbix,WeADMIN ITOSS亲测分享
- android程序内多语言切换不需要重新启动的解决方案
- 使用python进行爬虫学习(一)
- GitHub和SourceTree入门教程
- vc导出listcontrol界面值到excel最简单的例子
- apple Pay
- 文章标题