简单题

Ugly Number

My Submissions

Question
Total Accepted: 32635 Total Submissions: 94009 Difficulty: Easy

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的更多相关文章

  1. 【POJ2104】【HDU2665】K-th Number 主席树

    [POJ2104][HDU2665]K-th Number Description You are working for Macrohard company in data structures d ...

  2. 【SPOJ】NUMOFPAL - Number of Palindromes(Manacher,回文树)

    [SPOJ]NUMOFPAL - Number of Palindromes(Manacher,回文树) 题面 洛谷 求一个串中包含几个回文串 题解 Manacher傻逼题 只是用回文树写写而已.. ...

  3. 【LeetCode】Largest Number 解题报告

    [LeetCode]Largest Number 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/largest-number/# ...

  4. 【LeetCode】792. Number of Matching Subsequences 解题报告(Python)

    [LeetCode]792. Number of Matching Subsequences 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://f ...

  5. 【LeetCode】673. Number of Longest Increasing Subsequence 解题报告(Python)

    [LeetCode]673. Number of Longest Increasing Subsequence 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https:/ ...

  6. 【LeetCode】Single Number I & II & III

    Single Number I : Given an array of integers, every element appears twice except for one. Find that ...

  7. 【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 ...

  8. 【leetcode78】Single Number II

    题目描述: 给定一个数组,里面除了一个数字,其他的都出现三次.求出这个数字 原文描述: Given an array of integers, every element appears three ...

  9. 【u020】Couple number

    Time Limit: 1 second Memory Limit: 128 MB [问题描述] 任何一个整数N都能表示成另外两个整数a和b的平方差吗?如果能,那么这个数N就叫做Couple numb ...

随机推荐

  1. PTA Insertion or Heap Sort

    According to Wikipedia: Insertion sort iterates, consuming one input element each repetition, and gr ...

  2. 选择c3p0作为连接池

    <hibernate-configuration>     <session-factory>         <property name="dialect& ...

  3. C# 将文件嵌入DLL 。Log4net 配置

    最近在弄使用Log4net记录日志. 将配置文件封装到的DLL中. 封装步骤: 1.将配置文件添加到类库中. 2.在配置文件上右键,选择属性. 3. 此时生成类库.DLL中就存在该配置文件啦.如图: ...

  4. Computer Vision 学习 -- 图像存储格式

    本文把自己理解的图像存储格式总结一下. 计算机中的数据,都是二进制的,所以图片也不例外. 这是opencv文档的描述,具体在代码里面,使用矩阵来进行存储. 类似下图是(BGR格式): 图片的最小单位是 ...

  5. PTGM and APTM

    1. 性能测试过程模型(PTGM) PTGM模型包括以下几个步骤: 测试前期的准备 测试工具的引入 测试计划 测试设计与开发 测试执行与管理 测试分析 测试前期准备:主要任务为保证系统稳定和建立合适的 ...

  6. 使用Fiddler针对Android手机网络请求抓包

    本文转载自大牛Trinea的博文:Android利用Fiddler进行网络数据抓包 主要介绍Android及IPhone手机上如何利用Fiddler进行网络数据抓包,比如我们想抓某个应用(微博.微信. ...

  7. xcode5.1+osx.10.9编译x264的问题

    最近忙于编译x264开源框架进行视频编码,百度了很多方法没有实现.很多方法都过时了.根本不能成功.因为在xcode5以后,编译器不在默认为gcc,而是Apple自带的clang编译器.本人试了很多方法 ...

  8. HTML5 CSS3学习

    HTML5 CSS3学习 :http://www.1000zhu.com/course/css3/ HTML5 相关书籍:   http://www.html5cn.com.cn/news/gdt/2 ...

  9. listbox 报错 Cannot have multiple items selected when the SelectionMode is Single.

    1.错误提示:Cannot have multiple items selected when the SelectionMode is Single. 刚刚在处理两个Listbox时,将其中一个li ...

  10. spring 事务:注解方式

    (1) .<context:component-scan base-package="*.*" /> 该配置隐式注册了多个对注解进行解析的处理器,如: Autowire ...