简单题

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. oracle 数据库学习3 --oracle 数据库中常使用的函数

    1.字符函数: ASCII(X) -->返回X字符的ASCII码 concat(x,y)-->将y连接到X上输出 select concat(first_name,last_name) f ...

  2. cocos2dx中常见设计模式

    1.单例设计模式:导演类 2.观察者模式: 被观察者含有一个数组,里边存放了所有观察者的引用,在被观察者的状态发生改变的时候,通过调用观察者的函数来通知观察者,实现了信息的传递.  事件监听器:就是采 ...

  3. hdu4578 Transformation

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4578 题目大意:n个数(初始为0)m个操作,操作类型有4种,操作1把区间的每个数+a,操作2把区间的每 ...

  4. django单元测试

        django 单元测试小结 django 测试 从前很少写单元测试了,特别是web应用.最近不知不觉喜欢起来这个事情了,发现单元测试对于软件的模块,正交性有很大促进作用,因为函数,模块写的不合 ...

  5. 利用googleapis在日文系统中改善中文字

    加入以下两句 1. <head> <link rel="stylesheet" href="http://fonts.googleapis.com/ea ...

  6. ZT 螨虫知识2

    病情分析:过敏是治不好的,只能做到避免接触.指导意见:螨虫的话就不要跟狗多接触,狗的寄生虫很多,还有草地,尤其是狗经常去的地方,草地就是螨虫的传播介质.你是过敏性体质除了被免过敏性源外,还要增强体质, ...

  7. Java广度优先爬虫示例(抓取复旦新闻信息)

    一.使用的技术 这个爬虫是近半个月前学习爬虫技术的一个小例子,比较简单,怕时间久了会忘,这里简单总结一下.主要用到的外部Jar包有HttpClient4.3.4,HtmlParser2.1,使用的开发 ...

  8. 获取WIFI的SSID和本机IP

    1.获取WIFI的SSID 引入库 #import <SystemConfiguration/CaptiveNetwork.h> ..... ..... // WIFI的名字 + (NSS ...

  9. httpServletRequest对象、filter、servlet、servlet容器、catalina、tomcat、以及web容器之间的关系

    学习servlet的时候经常感到疑惑 HttpServletRequest是服务器创建的?还是servlet容器创建的? 过滤器是服务器创建的?还是servlet容器创建的? serlet容器和tom ...

  10. 期许伟大-基于CMMI的过程改进之道探索

    原文作者:上海科维安信息技术顾问有限公司QAI China 何丹博士 CMMI主任评估师   一.引子     近年来,由美国SEI  (软件工程研究所)开发的SW-CMM  (软件过程能力成熟度模型 ...