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. Oracle的回收站和闪回查询机制(一)

    实际工作中,我们经常会遇到一些情况,误删除某些表或某些表的某些记录,这时候就需要我们将这些记录重新插入进去.如何才能解决这个问题呢? Oracle的Flashback query(闪回查询)为我们解决 ...

  2. Linux查看物理内存信息

    Linux查看物理内存信息 1. 查看内存大小 dmidecode|grep Size 输出 Runtime Size: 64 kB ROM Size: 4608 kB Installed Size: ...

  3. 树莓派加入定时任务实现花生壳定时重启(linux的定时任务)

    由于花生壳在linux下不稳定,联系开机一个星期左右会挂掉,所以要使用定时任务实现每小时刷新一次/启动一次. 使用的是linux下的定时任务crontab去实现. 实现步骤: 1.编辑/etc/cro ...

  4. hashCode()和equals()的用法

    使用hashCode()和equals() hashCode()和equals()定义在Object类中,这个类是所有java类的基类,所以所有的java类都继承这两个方法. hashCode()方法 ...

  5. 【Java】多线程冲突解决——同步锁

       转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/5827547.html    解决并行冲突最有效的方法就是加同步锁,主要有以下几种方法:   1:动态方法 ...

  6. Enterprise Library 4 数据访问应用程序块

    Enterprise Library 数据访问应用程序块简化了实现常规数据访问功能的开发任务.应用程序可以在各种场景中使用此应用程序块,例如为显示而读取数据.传递数据穿过应用程序层( applicat ...

  7. Myeclipse 10.x 安装Aptana3.2 插件

    安装步骤: 1.下载aptana3.2 Eclipse Plugin插件. 下载地址:http://update1.aptana.org/studio/3.2/024747/index.html 2. ...

  8. Python beautifulsoup模块

    BeautifulSoup中文文档:https://www.crummy.com/software/BeautifulSoup/bs4/doc.zh/ BeautifulSoup下载:http://w ...

  9. securecrt 连接vmware ubuntu

    折腾了好几天,我只想说shit,吃一堑长一智,和大家分享. SecureCRT连接Linux是使用Ubuntu下的SSH服务,ssh包括客户端和服务端即openssh-client,openssh-s ...

  10. PostgreSQL的 initdb 源代码分析之二

    继续分析 下面这一段,当 initdb --version 或者  initdb --help 才有意义. ) { ], || strcmp(argv[], ) { usage(progname); ...