public class Solution {
private bool Judge(int x)
{
if (x <= )
{
return false;
}
int bound = Convert.ToInt32(Math.Sqrt(x)); for (int i = ; i <= bound; i++)
{
if (x % i == )
{
return false;
}
}
return true;
} //素数筛法
private List<int> init(int num)
{
var prime = new List<int>();
bool[] mark = new bool[num + ];
for (int i = ; i <= num; i++)
{
mark[i] = false;
} for (int i = ; i <= num; i++)
{
if (mark[i])//排除2,3,5
{
continue;
}
prime.Add(i);
for (int j = i * i; j < num + ; j += i)
{
mark[j] = true;
}
}
return prime;
} public bool IsUgly(int num)
{
if (num <= ) { return false; }
if (num == ) { return true; }
if (num % == )
{
return IsUgly(num / );
}
if (num % == )
{
return IsUgly(num / );
}
if (num % == )
{
return IsUgly(num / );
}
return false;
}
}

https://leetcode.com/problems/ugly-number/#/description

本题同剑指Offer49

leetcode263的更多相关文章

  1. LeetCode----263. Ugly Number(Java)

    package isUgly263; /* * Write a program to check whether a given number is an ugly number. Ugly numb ...

  2. [Swift]LeetCode263. 丑数 | Ugly Number

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

  3. LeetCode263:Ugly Number

    public bool IsUgly(int num) { if(num<1) return false; while(num>1) { if(num%2==0) { num=num/2; ...

  4. LeetCode263——Ugly Number

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

  5. LeetCode 263

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

随机推荐

  1. 《DSP using MATLAB》Problem 4.12

    代码: function [As, Ac, r, v0] = invCCPP(b0, b1, a1, a2) % Determine the signal parameters Ac, As, r, ...

  2. sys目录下常用文件汇总

    1. /sys/kernel/debug/gpio 可以实时反馈系统中感兴趣的gpio引脚的状态 root@g6s:/sys/kernel/debug# cat gpio gpiochip7: GPI ...

  3. 对象的继承(__proto__和Object.setPrototypeOf(child,father))

    两个对象间的继承

  4. 罗技 M558 鼠标维修记录

    罗技 M558 鼠标维修记录 故障现象 按键不灵敏 拆机内部图 前进键 后退键 左键 右键 中键 自定义功能键 使用的是 OMRON 按键,好东西,质量可以. 但毕竟是机械的东西,还是有老化,用万用表 ...

  5. php 使用 file_exists 还是 is_file

    Jesns 提出 file_exists 比较老了,建议使用 is_file 来判断文件. 经过我的测试,is_file 果然快很多,以后可以改 is_file 来判断文件. 还有相关链接: is_f ...

  6. [CLPR] 卷积还是相关? - Opencv之filter2D探究

    I am doing something about convolving images in Python and for sake of speed I chose opencv 2.4.9. O ...

  7. es 之 Symbol

    ES5 的对象属性名都是字符串,这容易造成属性名的冲突.比如,你使用了一个他人提供的对象,但又想为这个对象添加新的方法(mixin 模式),新方法的名字就有可能与现有方法产生冲突.如果有一种机制,保证 ...

  8. yii2 rbac权限管理学习笔记

    下面介绍一个 yii2 的 Rbac 权限管理设置,闲话少说,直接上代码, 1.首先我们要在组件里面配置一下 Rbac ,如下所示(common/config/main-local.php或者main ...

  9. VBox修改uuid

    1.使用VBoxManage命令时,需要先在命令行中切换到VirtualBox的安装目录下 2.修改vdi的uuid:VBoxManage internalcommands sethduuid  D: ...

  10. Linq快速入门——Lambda表达式的前世今生

    Linq快速入门——Lambda表达式的前世今生   Lambda表达式其实并不陌生,他的前生就是匿名函数,所以要谈Lambda表达式,就不得不谈匿名函数,要谈匿名函数,那又要不得不谈委托. 何为委托 ...