204. Count Primes (Integer)
Count the number of prime numbers less than a non-negative number, n.
思路:寻找质数的方法
class Solution {
public:
int countPrimes(int n) {
int num = ;
if(n < ) return num; int i, j, index;
isPrime = new bool [n];
isPrime[]=false;
isPrime[]=false;
for(i = ; i < n; i++){
isPrime[i] = true;//initialize as true, means all are primes
} for(i = ; i < n; i++){
if(!isPrime[i]) continue; num++;
for(j=; i*j < n; j++){
isPrime[i*j] = false;
}
} return num;
}
private:
bool* isPrime;
};
204. Count Primes (Integer)的更多相关文章
- [leetcode] 204. Count Primes 统计小于非负整数n的素数的个数
题目大意 https://leetcode.com/problems/count-primes/description/ 204. Count Primes Count the number of p ...
- 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 ...
- 204. Count Primes - LeetCode
Queston 204. Count Primes Solution 题目大意:给一个数,求小于这个数的素数的个数 思路:初始化一个boolean数组,初始设置为true,先遍历将2的倍数设置为fal ...
- 【刷题-LeetCode】204. Count Primes
Count Primes Count the number of prime numbers less than a non-negative number, *n*. Example: Input: ...
- [LeetCode] 204. Count Primes 质数的个数
Count the number of prime numbers less than a non-negative number, n. Example: Input: 10 Output: 4 E ...
- [LeetCode] 204. Count Primes 计数质数
Description: Count the number of prime numbers less than a non-negative number, n click to show more ...
- 【LeetCode】204 - Count Primes
Description:Count the number of prime numbers less than a non-negative number, n. Hint: Let's start ...
- Java [Leetcode 204]Count Primes
题目描述: Description: Count the number of prime numbers less than a non-negative number, n. 解题思路: Let's ...
- LeetCode 204 Count Primes
Problem: Count the number of prime numbers less than a non-negative number, n. Summary: 判断小于某非负数n的质数 ...
随机推荐
- 在keil调用Notepad++
先打开keil, 新建一个 取名为notepad 选择notepad++的安装路径 设置参数 保持后可以看多了notepad的选项 运行当前的文件在notepad++打开
- Srping cloud Ribbon 自定义负载均衡
IRule 默认提供有7种方式,使用轮询方式 如何自定义 1:主启动类加@RibbonClient @RibbonClient(name="微服务名", configuration ...
- greenplum
参考文章:在linux系统上安装Greenplum数据库 https://blog.csdn.net/mingli_a/article/details/78779189 Greenplum安装步骤 ...
- 【372】Kaggle 相关经验
参考:机器学习系列(3)_逻辑回归应用之Kaggle泰坦尼克之灾 参考:Kaggle泰坦尼克特征工程和模型融合 『解决一个问题的方法和思路不止一种』『没有所谓的机器学习算法优劣,也没有绝对高性能的机器 ...
- MVC之Model元数据
Contronoller激活之后,ASP.NET MVC会根据当前请求上下文得到目标Action的名称,然后解析出对应的方法并执行之. 在整个Action方法的执行过程中,Model元数据的解析是一个 ...
- 16进制转ascii,转字符串
/** * 16进制转化为字母 * @param hex 要转化的16进制数,用逗号隔开 * 如:53,68,61,64,6f,77 * @return */ public static String ...
- SimpleDateFormat 使用时出现的线程同步问题。。。
错误使用: public static final SimpleDateFormat DAY_UI_MONTH_DAY_FORMAT = new SimpleDateFormat("MM-d ...
- 【转】使用SecureCRT连接ubuntu
1. Ubuntu 装好之后默认是没有安装ssh服务的(我的版本是Ubuntu 12.04.3 LTS),需要手动安装: 安装命令:sudo apt-get install openssh-ser ...
- VPS 相关
1.一键测试 wget http://soft.laozuo.org/tools/cpu-io.shsh cpu-io.sh 2.锐速破解 wget -N --no-check-certificate ...
- Hibernate 再接触 关系映射 一对一单向外键联合主键关联
例子: Husband.java package com.bjsxt.hibernate; import javax.persistence.Entity; import javax.persiste ...