【13_263】Ugly Number
简单题
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.
Discuss中总有惊喜:
Java:
for (int i=2; i<6 && num>0; i++)
while (num % i == 0)
num /= i;
return num == 1;
Python:
for p in 2, 3, 5:
while num % p == 0 < num:
num /= p
return num == 1
C++:(其中&&之后的num怎么理解?)
for (int i=; i< && num; i++)
while (num % i == )
num /= i;
return num == ;
自己的:
C++:
class Solution {
public:
bool isUgly(int num) {
if (num <= )
return false;
if (num == )
return true;
while (num != ) {
if (num % == ) {
num = num / ;
}
else if (num % == ) {
num = num / ;
}
else if (num % == ) {
num = num / ;
}
else{
return false;
}
}
return true;
}
};
【13_263】Ugly Number的更多相关文章
- 【POJ2104】【HDU2665】K-th Number 主席树
[POJ2104][HDU2665]K-th Number Description You are working for Macrohard company in data structures d ...
- 【SPOJ】NUMOFPAL - Number of Palindromes(Manacher,回文树)
[SPOJ]NUMOFPAL - Number of Palindromes(Manacher,回文树) 题面 洛谷 求一个串中包含几个回文串 题解 Manacher傻逼题 只是用回文树写写而已.. ...
- 【LeetCode】Largest Number 解题报告
[LeetCode]Largest Number 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/largest-number/# ...
- 【LeetCode】792. Number of Matching Subsequences 解题报告(Python)
[LeetCode]792. Number of Matching Subsequences 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://f ...
- 【LeetCode】673. Number of Longest Increasing Subsequence 解题报告(Python)
[LeetCode]673. Number of Longest Increasing Subsequence 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https:/ ...
- 【LeetCode】Single Number I & II & III
Single Number I : Given an array of integers, every element appears twice except for one. Find that ...
- 【HDU3948】 The Number of Palindromes (后缀数组+RMQ)
The Number of Palindromes Problem Description Now, you are given a string S. We want to know how man ...
- 【leetcode78】Single Number II
题目描述: 给定一个数组,里面除了一个数字,其他的都出现三次.求出这个数字 原文描述: Given an array of integers, every element appears three ...
- 【u020】Couple number
Time Limit: 1 second Memory Limit: 128 MB [问题描述] 任何一个整数N都能表示成另外两个整数a和b的平方差吗?如果能,那么这个数N就叫做Couple numb ...
随机推荐
- MySQL root密码找回
以MySQL多实例为例,演示找回MySQL root的密码 1.关闭mysql服务 [root@mysql ~]# mysqladmin -uroot -poldboy123 -S /data/330 ...
- git代理设置方法解决
git config --global https.proxy http://127.0.0.1:1080 git config --global https.proxy https://127.0. ...
- 【Python全栈笔记】01 [模块二] 14-15 Oct 运算符和字符串 4-1
编码的问题 中文版 Windows 终端是默认GBK编码格式,python2默认为ASCII编码,虽然我们注释了需要用UTF-8,但是通过命令行运行的文件如果print中文内容还是会出现乱码. Uni ...
- linux学习笔记--文件
文件系统 ls -lhi i inode 相当于文件在磁盘里的唯一标示,index node h 代表文件大小k,m [root@masters ~]# [root@masters ~]# ls -l ...
- 图解 classpath
先引用几句网上流传的话: 首先 classpath是指 WEB-INF文件夹下的classes目录 classpath 和 classpath* 区别: classpath:只会到你指定的class路 ...
- 最近遇到的jsfl开发问题总结
最近在用jsfl开发一套把MUGEN角色动画和数据导入flash的脚本.遇到不少问题,这里备忘一下: 1.绘制笔刷和填充的问题 更换填充和笔刷需要用如下的代码 而不是随便设置一下doc的属性 var ...
- AJAX同步改异步
var temp; $.ajax({ async: false, type : "POST", url : defaultPostData.url, dataType : 'jso ...
- shift
-------siwuxie095 shift 更改批处理文件中可替换参数的位置 语法: SHIFT [/n] 如果命令扩展被启用,SHIFT 命令支持 /n 命令行开关:该命令行开关告诉 命令从第 ...
- 解决跑twoBitToFa时出现“/admin/exe/linux.x86_64/twoBitToFa: Permission denied”的问题
出现这种问题时,一般要加上以下命令: chmod ugo+x ./admin/exe/linux.x86_64/twoBitToFa 运行成功后,再将twobit格式转化为fa格式 ./admin/e ...
- Android-MediaRecorder-音频录制-警告-W/MediaRecorder(13811): mediarecorder went away with unhandled events
Android-MediaRecorder-音频录制-警告-W/MediaRecorder(13811): mediarecorder went away with unhandled events ...