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 ...
随机推荐
- HDU 5833 Zhu and 772002 (高斯消元)
Zhu and 772002 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5833 Description Zhu and 772002 are b ...
- PID参数整定快速入门(调节器参数整定方法)
PID调节器参数整定方法很多,常见的工程整定方法有临界比例度法.衰减曲线法和经验法.云润仪表以图文形式分别介绍调节器参数整定方法. 临界比例度法一个调节系统,在阶跃干扰作用下,出现既不发散也不衰减的等 ...
- ALAsset,ALAssetsLibrary,ALAssetsgroup常见属性及用法
转载自 http://www.cnblogs.com/javawebsoa/archive/2013/07/19/3201246.html ALAssetsgroup --------------- ...
- oracle 的rowid和rownum
rowid就是唯一标志记录物理位置的一个id,对于rownum来说它是oracle系统顺序分配为从查询返回的行的编号,返回的第一行分配的是1,第二行是2,依此类推,这个伪字段可以用于限制查询返回的总行 ...
- POJ 3041 Asteroids (二分图最小点覆盖)
题目链接:http://poj.org/problem?id=3041 在一个n*n的地图中,有m和障碍物,你每一次可以消除一行或者一列的障碍物,问你最少消除几次可以将障碍物全部清除. 用二分图将行( ...
- UVa 10817 Headmaster's Headache (状压DP+记忆化搜索)
题意:一共有s(s ≤ 8)门课程,有m个在职教师,n个求职教师.每个教师有各自的工资要求,还有他能教授的课程,可以是一门或者多门. 要求在职教师不能辞退,问如何录用应聘者,才能使得每门课只少有两个老 ...
- HTML5学习笔记(一):HTML简介
Web前端涵盖的内容较多且杂,主要由3个部分组成:HTML标记语言.CSS样式语言和JavaScript脚本语言组成,而下面我们将先学习最新的标记语言HTML5. <!DOCTYPE>标记 ...
- C++中标准容器Vector,元素操作.insert()小结
insert() 函数有以下三种用法: iterator insert( iterator loc, const TYPE &val ); //在指定位置loc前插入值为val的元素,返回指 ...
- Redis学习_01 windows下的环境搭建
一.Redis 简介 redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合).zset( ...
- Mysql,JDBC封装
1.完成对数据库的表的增删改的操作 2.查询返回单条记录 3.查询返回多行记录 4.可以使用反射机制来封装,查询单条记录 5.反射机制,查询多条记录 package myjdbc; import ja ...