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. Linux上svn服务器的搭建

    安装svn服务器 直接用yum安装,命令如下: #yum install -y subversion 验证是否安装成功. #svnserve --version 创建SVN版本库 在home目录下创建 ...

  2. [iOS基础控件 - 6.10.7] UIWindow

    A.UIWindow概念 1.继承UIView,是一种特殊的UIView 2.通常一个APP只有一个UIWindow 3.iOS程序启动后,创建的第一个视图就是UIWindow 4.没有UIWindo ...

  3. HDU1028Ignatius and the Princess III(母函数)

    http://acm.hdu.edu.cn/showproblem.php?pid=1028 母函数: 例1:若有1克.2克.3克.4克的砝码各一 枚,能称出哪几种重量?各有几种可能方案? 如何解决这 ...

  4. C++ Lambda表达式用法

    C++ 11中的Lambda表达式用于定义并创建匿名的函数对象,以简化编程工作. Lambda的语法形式如下: [函数对象参数] (操作符重载函数参数) mutable或exception声明 -&g ...

  5. Unity中2D和UGUI图集的理解与使用

    图集 什么是图集? 在使用3D技术开发2D游戏或制作UI时(即使用GPU绘制),都会使用到图集,而使用CPU渲染的2D游戏和UI则不存在图集这个概念(比如Flash的原生显示列表),那么什么是图集呢? ...

  6. VBA在Excel中的应用(一):改变符合条件单元格的背景颜色

    在使用excel处理数据的时候,为了能更清晰的标示出满足特定条件的单元格,对单元格添加背景色是不错的选择.手工处理的方式简单快捷,但是当遇到大批量数据,就会特别的费时费力,而且不讨好(容易出错).通过 ...

  7. nginx将http重定向到https

    1.rewrite server { listen 80; server_name test.com; rewrite ^(.*)$ https://$host$1 permanent; } 2. n ...

  8. linx目录结构

    linux中的命令一般存放在/bin目录下的: 以下为linux下的基本目录结构和作用: /根目录./boot引导程序,内核等存放的目录./sbin超级用户可以使用的命令的存放目录./bin普通用户可 ...

  9. VHD_Update_mount-vhd

    ###################功能说明########################该脚本用来对离线VHD文件更新,导入系统补丁############################### ...

  10. Android Studio安装及主题字体配置

    在2013 Google I/O 大会上,谷歌推出了自家全新的安卓软件集成开发工具 Android Studio,这是 Google 基于 IntelliJ IDEA 改动而来. 谷歌称 Androi ...