丑数-LintCode
来源:互联网 发布:完全卸载sqlserver 编辑:程序博客网 时间:2024/05/29 14:31
写一个程序来检测一个整数是不是丑数。
丑数的定义是,只包含质因子 2, 3, 5 的正整数。比如 6, 8 就是丑数,但是 14 不是丑数以为他包含了质因子 7。
注意事项:
可以认为 1 是一个特殊的丑数。
样例:
给出 num = 8,返回 true。
给出 num = 14,返回 false。
#ifndef C517_H#define C517_H#include<iostream>using namespace std;class Solution {public: /* * @param num: An integer * @return: true if num is an ugly number or false */ bool isUgly(int num) { // write your code here if (num <= 0) return 0; if (num == 1) return true; if (num % 5 != 0 && num % 3 != 0 && num % 2 != 0) return false; else { if (num % 5 == 0) return isUgly(num / 5); else if (num % 3 == 0) return isUgly(num / 3); else return isUgly(num / 2); } }};#endif
阅读全文
0 0
- LintCode 丑数
- LintCode-丑数
- lintcode-丑数 II
- LintCode:超级丑数
- LintCode 517 丑数
- LintCode.517.丑数
- 丑数-LintCode
- 超级丑数-LintCode
- LintCode 4 丑数II
- LintCode Python 丑数II
- [LintCode]4.丑数 II
- LintCode----4.丑数II
- LintCode 4.丑数 II
- LintCode-剑指Offer-(4)丑数
- **[Lintcode]Ugly Number II 丑数 II
- lintcode python代码 517丑数
- LintCode python 小白5-丑数
- Google/LintCode:M-超级丑数
- cf 6789 this one ttt
- 固态硬盘的了解
- tensorflow 的tensorboard使用
- 用redis实现支持优先级的消息队列
- SSH 端口转发实战
- 丑数-LintCode
- 李国杰院士:AI创业公司如何摆脱被收购的命运「附雷克世界专访」
- 不是技术大牛,如何拿到国内IT巨头的offer
- Wine 编译安装-中文设置
- 2017.10.27开始学习FFMPEG音视频编解码,通过学习雷霄骅文章
- spark基础之shuffle机制和原理分析
- Cookie和Session的区别
- Strus2 页面传输数据到后台(普通属性传值,模型驱动传值,域对象传值,OGNL表达式传值)
- Font字体