leetcode263
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的更多相关文章
- LeetCode----263. Ugly Number(Java)
package isUgly263; /* * Write a program to check whether a given number is an ugly number. Ugly numb ...
- [Swift]LeetCode263. 丑数 | Ugly Number
Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers ...
- LeetCode263:Ugly Number
public bool IsUgly(int num) { if(num<1) return false; while(num>1) { if(num%2==0) { num=num/2; ...
- LeetCode263——Ugly Number
Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers ...
- LeetCode 263
Ugly Number Write a program to check whether a given number is an ugly number. Ugly numbers are posi ...
随机推荐
- smarty学习——缓存
存被用来保存一个文档的输出从而加速display()或fetch()函数的执行.如果一个函数被加进缓存,那么实际输出的内容将用缓存来代替. 缓存可让事物非常快速的执行,特别是带有长计算时间的模板.一旦 ...
- 根据IP获得城市信息(百度API的运用)
/** * 根据IP获取城市 * @param string $ip ip地址 * @return array * http://api.map.baidu.c ...
- Word中回车和网页换行替换
回车^p 换行^l 用编辑中的查找替换即可 查找^l,替换为^p (一)有建议说按Delete键一个一个将其删除,这是麻烦的,其实可用WORD的查找替换工具一次性替换成回车符.查找--点特殊字符--手 ...
- Microsoft Dynamics CRM 4.0 如何添加自定义按钮
一.通过导入导出ISV.Config(ISV配置),具体如下图: 先设置—>打开导出自定义项—>选择ISV配置—>选择导出所选自定义项 点击确定 保存到桌面,解压,用VS打开cust ...
- Cenots7对lvm逻辑卷分区大小的调整
Cenots7对lvm逻辑卷分区大小的调整 (针对xfs和ext4不同文件系统) 1.支持的文件系统类型 特别注意的是: resize2fs命令 针对的是ext2.ext3.ex ...
- ASP.NET 实现验证码以及刷新验证码
实现代码 /// <summary> /// 生成验证码图片,保存session名称VerificationCode /// </summary> public static ...
- oracle 恢复备份
select * from dbconninfo update dbconninfo set url = 'jdbc:oracle:thin:@(description=(address_list=( ...
- 【C#】string格式的日期转为DateTime类型及时间格式化处理方法
日期格式:yyyyMMdd HH:mm:ss(注意此字符串的字母大小写很严格) yyyy:代表年份 MM: 代表月份 dd: 代表天 HH: 代表小时(24小时制) mm: 代表分钟 ss: 代表秒 ...
- bzoj 4929: 第三题
Description 给定n,b,c,d,e以及A0,A1,···,An−1,定义 xk=b×c^4k+d×c^2k+e f(x)=Sigma(Aix^i),0<=i<=n-1 请你求出 ...
- web服务器检测
# coding=utf-8 import sys import socket import re def check_webserver(address, port, resource): addr ...