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的质数 ...
随机推荐
- <基础> PHP 数据类型
PHP三大数据类型 标量 字符串 单引号:不能解析变量 效率高 双引号 :可以解析变量 效率稍微低一些 heredoc : 大文本 整形 浮点 不能用于比较运算 布尔 复合 数组 超全局数组 ...
- react-native-picker 实现省市区 时间日期组件
github示例以及详细参数:https://github.com/beefe/react-native-picker 先 安装 link npm install react-native-picke ...
- RabbitMq(2) 简单消息队列
<dependency> <groupId>com.rabbitmq</groupId> <artifactId>amqp-client </ar ...
- [转]让linux的coredump文件
原文标题:gdb结合coredump定位崩溃进程 原文:http://lazycat.is-programmer.com/posts/31925.html 这个文件中说的方法我试过了,在CentOS和 ...
- jquery 基础-记住
jquery最为一个库,简便. 难点在于选择器,筛选器的使用. 属性一般都是,jquery对象.函数(),括号内部添属性. s= '<tr> <td class="fix& ...
- Django - cookies 会话跟踪技术
一.HTTP协议的无状态保存 两次请求之间没有关联 会话理解为客户端与服务器之间的一次会晤,在一次会晤中可能会包含多次请求和响应 2.会话路径技术使用Cookie或session完成 我们知道HTTP ...
- virtual 初探
两种代码方式: class person { public: void f() { cout << "person.f()" << endl; } }; c ...
- easy.py使用中ValueError: could not convert string to float: svm_options错误问题解决
在使用easy.py中出现如下图所示问题 解决方法: 1.找到cmd = '{0} -svmtrain "{1}" -gnuplot "{2}" "{ ...
- 1005 继续(3n+1)猜想 (25 分)
1005 继续(3n+1)猜想 (25)(25 分) - 过期汽水的博客 - CSDN博客https://blog.csdn.net/qq_40167974/article/details/80739 ...
- jenkins+docker+docker-compose完整发版流程
首先搭建jenkins+maven+nexus这一套自动化打包工具,并配置好相应配置,这里就不再赘述了. 其次,搭建好docker集群和私有仓库,以及安装好docker-compose工具,配置好相应 ...