LeetCode 263
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的更多相关文章
- 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 ...
- [LeetCode] 263. Ugly Number 丑陋数
Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers ...
- 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 ...
- 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 ...
- Java实现 LeetCode 263 丑数
263. 丑数 编写一个程序判断给定的数是否为丑数. 丑数就是只包含质因数 2, 3, 5 的正整数. 示例 1: 输入: 6 输出: true 解释: 6 = 2 × 3 示例 2: 输入: 8 输 ...
- LeetCode 263 Ugly Number
Problem: Write a program to check whether a given number is an ugly number. Ugly numbers are positiv ...
- Leetcode 263 Ugly Number 数论 类似质因数分解
Ugly Number的质因数仅为2,3,5 将输入的数分别除以2,3,5直到不能除,看是否为1,为1的是Ugly Number,其他则不是. class Solution { public: boo ...
- (easy)LeetCode 263.Ugly Number
Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers ...
- Java [Leetcode 263]Ugly Number
题目描述: Write a program to check whether a given number is an ugly number. Ugly numbers are positive n ...
随机推荐
- 使用bootstrap的html文件转换成jsp…
问题:使用bootstrap的html文件转换成jsp时表单高度变窄 解决方法: 将jsp中html文档类型修改为<!DOCTYPE html> 问题即可解决. 也就是bootstrap只 ...
- HDU 5656 CA Loves GCD (数论DP)
CA Loves GCD 题目链接: http://acm.hust.edu.cn/vjudge/contest/123316#problem/B Description CA is a fine c ...
- Spring 使用注解方式进行事物管理
大家在使用spring的注解式事务管理时,对事务的传播行为和隔离级别可能有点不知所措,下边就详细的介绍下以备方便查阅. 事物注解方式: @Transactional 当标于类前时, 标示类中所有方法都 ...
- Windows安全模式的妙用
使用计算机的老手一定对windows安全模式不陌生,在删除病毒,卸载顽固软件,或者系统维护时,Windows的安全模式肯定会帮助很大,下面电脑技术就说说Windows安全模式的作用以及用处. wind ...
- JS与Jquery的事件委托——解决了绑定相同事件的问题
概念: 什么是事件委托:通俗的讲,事件就是onclick,onmouseover,onmouseout,等就是事件,委托呢,就是让别人来做,这个事件本来是加在某些元素上的,然而你却加到别人身上来做,完 ...
- 关于TCP主动关闭连接中的wait_timeout
首先我们先来回顾一下tcp关闭连接的过程: 假设A和B连接状态为EST,A需要主动关闭: A发送FIN给B,并将状态更改为FIN_WAIT1, B接收到FIN将状态更改为CLOSE_WAIT,并回复A ...
- ios开源项目(各种有用的第三方库)
状态栏:MTStatusBarOverlay 下拉刷新:EGOTableViewPullRefresh 网络应用:ASIHTTPRequest 等待特效:MBProgressHUD JSON解 ...
- iOS-default.png启动图片
我在xcode5下写的代码,我下载了iOS6的模拟器,我用iOS6和iOS7的模拟器切换运行,有的时候可以运行有的时候不可以运行,报错: 2013-11-17 16:49:04.049 sim[474 ...
- CESAsia:英特尔RealSense3D实感技术亮眼
每年CES展会上都会有许多新奇的.更具创意的产品和创新技术亮相,而作为全球科技盛会之一的CES Asia也不例外.在CES Asia2016展会上,英特尔(Intel)可谓是有备而来,带着旗下支持Re ...
- C++ 对象没有显式初始化
C++ 对象没有显式初始化,结果是什么? 首先考虑非静态对象 1.方法内的局部对象: a.类类型:调用default构造方法 b.基本类型:值不确定 2.类中的数据成员: a.类类型:调用defaul ...