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的质数 ...
随机推荐
- inno setup 安装前判断进程是否存在,以及停止相应进程<转>
打包的时候遇到了这样的需求:假似用户都是傻瓜 式操作,如果更新安装程序的时候,之前的老程序还在运行这个时候如果你去提示让用户吧老程序手动退掉也不现实. 所以当遇到这种 ...
- mui longtap 事件无效
1.mui 的部分事件默认是关闭的 需要在init中单独配置事件开关 mui.init({ gestureConfig: { longtap: true, //默认为false } })
- C#反射机制详解
反射的定义:审查元数据并收集关於它的类型信息的能力,元数据(编辑后的基本数据单元)就是一大堆表,编译器会创建一个类定义表,一个字段定义表,一个方法定义表等,System.Reflection命名空间包 ...
- C++复习:对C的拓展
简单的C++程序 求圆的周长和面积 数据描述: 半径,周长,面积均用实型数表示 数据处理: 输入半径 r: 计算周长 = 2*π*r : ...
- Win7下npm命令Error: ENOENT问题解决
Win7下在执行npm命令,比如npm list时出现下面错误:
- c# GC 新典型
public class testGC : MonoBehaviour { class XDict<K, V> { public void TryGetValue(K key, V val ...
- bat脚本基础教程
bat脚本就是DOS批处理脚本,就是将一系列DOS命令按照一定顺序排列而形成的集合,运行在windows命令行环境上.本文主要介绍bat脚本基础语法,希望完成本文内容学习之后具备基础的bat脚本开发能 ...
- python 获取命令行参数
https://www.cnblogs.com/captain_jack/archive/2011/01/11/1933366.html zzz.py import sys from optparse ...
- jira-6.0.1-x64下载地址
http://downloads.atlassian.com/software/jira/downloads/atlassian-jira-6.0.1-x64.bin
- Unity3D教程宝典之Shader篇
教程目录 基础讲:Shader学习方法基础讲:基础知识特别讲:常见问题解答特别讲:CG函数 第一讲: Shader总篇第二讲: Fixed Function Shader 第三讲: Vertex&am ...