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.

 /*   2ms     */

 public class Solution {

     int quyu(int a,int q){
while(a%q==0){
a=a/q;
}return a;
}
public boolean isUgly(int num) { if(num==0){
return false;
}
num=quyu(num,2);
num=quyu(num,3);
num=quyu(num,5); if(num==1){
return true;
}else{
return false;
}
}
}
 /*     5ms   */

 public class Solution {

     public boolean isUgly(int num) {

         if(num==0) return false;
while(num%2==0) num/=2;
while(num%3==0) num/=3;
while(num%5==0) num/=5; if(num==1) return true;
else return false;
}
}
 /*************************************************************************
> File Name: LeetCode263.c
> Author: Juntaran
> Mail: JuntaranMail@gmail.com
> Created Time: Wed 18 May 2016 19:45:08 PM CST
************************************************************************/ /************************************************************************* 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. ************************************************************************/ #include <stdio.h> int quyu( int num, int q )
{
while( num % q == )
{
num = num / q;
}
return num;
} int isUgly(int num)
{
if( num <= )
{
return ;
}
num = quyu( num, );
num = quyu( num, );
num = quyu( num, ); if( num == )
{
return ;
}
else
{
return ;
}
} int main()
{
int num = ;
int ret = isUgly(num);
printf("%d\n", ret);
}

LeetCode 263的更多相关文章

  1. leetcode@ [263/264] Ugly Numbers & Ugly Number II

    https://leetcode.com/problems/ugly-number/ Write a program to check whether a given number is an ugl ...

  2. [LeetCode] 263. Ugly Number 丑陋数

    Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers ...

  3. leetcode 263. Ugly Number 、264. Ugly Number II 、313. Super Ugly Number 、204. Count Primes

    263. Ugly Number 注意:1.小于等于0都不属于丑数 2.while循环的判断不是num >= 0, 而是能被2 .3.5整除,即能被整除才去除这些数 class Solution ...

  4. LN : leetcode 263 Ugly Number

    lc 263 Ugly Number lc 263 Ugly Number Write a program to check whether a given number is an ugly num ...

  5. Java实现 LeetCode 263 丑数

    263. 丑数 编写一个程序判断给定的数是否为丑数. 丑数就是只包含质因数 2, 3, 5 的正整数. 示例 1: 输入: 6 输出: true 解释: 6 = 2 × 3 示例 2: 输入: 8 输 ...

  6. LeetCode 263 Ugly Number

    Problem: Write a program to check whether a given number is an ugly number. Ugly numbers are positiv ...

  7. Leetcode 263 Ugly Number 数论 类似质因数分解

    Ugly Number的质因数仅为2,3,5 将输入的数分别除以2,3,5直到不能除,看是否为1,为1的是Ugly Number,其他则不是. class Solution { public: boo ...

  8. (easy)LeetCode 263.Ugly Number

    Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers ...

  9. Java [Leetcode 263]Ugly Number

    题目描述: Write a program to check whether a given number is an ugly number. Ugly numbers are positive n ...

随机推荐

  1. c函数调用过程原理及函数栈帧分析

    转载自地址:http://blog.csdn.net/zsy2020314/article/details/9429707       今天突然想分析一下函数在相互调用过程中栈帧的变化,还是想尽量以比 ...

  2. Struts2在Action中访问WEB资源

    什么是WEB资源? 这里所说的WEB资源是指:HttpServletRequest, HttpSession, ServletContext 等原生的 Servlet API. 为什么需要访问WEB资 ...

  3. 【转】iOS 硬件授权检测:定位服务、通讯录、日历、提醒事项、照片、蓝牙共享、麦克风、相机等

    iOS系统版本的不断升级的前提,伴随着用户使用设备的安全性提升,iOS系统对于App需要使用的硬件限制也越来越严格,App处理稍有不妥,轻则造成功能不可用用户还不知道,重则会造成App Crash. ...

  4. 贪心-poj-2437-Muddy roads

    题目链接: http://poj.org/problem?id=2437 题目意思: 给n个区间,每次可以用长度为L的棒A去覆盖,求将所有区间覆盖至少需要几次.给的区间不覆盖. 解题思路: 简单贪心. ...

  5. ecshop以幻灯版调用首页主广告显示

    默认的是index_ad.lbi模板有一个$flash变量了,但在搜索搜索没发现 <!--{foreach from=$flash name=no item=flash}--> <l ...

  6. PicklingError: Can't pickle <type 'generator'>: it's not found as __builtin_

    多进程传递 参数时,需要是python系统已知的,不然不知道怎么序列化

  7. weak nonatomic strong等介绍(ios)

    @property的属性weak nonatomic strong等介绍(ios) 2014-12-02 18:06 676人阅读 评论(0) 收藏 举报 学习ios也已经快半个月了,也尝试做简单的应 ...

  8. [转载代码]VB.NET 中查询 Linq to SQL 执行时的SQL语句

    在搜索使用LINQ TO SQL 添加数据后获得自增长ID的方法时,发现C#可以使用DebuggerWritter把使用Linq to SQL执行的SQL语句显示到即时窗口,于是在网上搜索到在VB.N ...

  9. cloudstack 修改显示名称

    http://192.168.153.245:8900/client/api?command=updateVirtualMachineid=922d15e1-9be0-44ac-9494-ce5afc ...

  10. Codeforces Round #185 (Div. 2) C. The Closest Pair 构造

    C. The Closest Pair Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/312/p ...