Leetcode 204. Count Primes

原创 2016年05月30日 17:07:54

Description:
Count the number of prime numbers less than a non-negative number, n.

下面这篇文章有详细解题思路:
http://www.cnblogs.com/zfyouxi/p/4907294.html

class Solution {
public:
    int countPrimes(int n) {
        vector<bool> prime(n, true);
        prime[0] = false, prime[1] = false;
        for (int i = 0; i < sqrt(n); ++i) {
            if (prime[i]) {
                for (int j = i*i; j < n; j += i) {
                    prime[j] = false;
                }    
            }    
        }
        return count(prime.begin(), prime.end(), true);
    }
};
版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

【leetcode】【204】Count Primes

一、问题描述 Description: Count the number of prime numbers less than a non-negative number, n. ...

Count Primes - LeetCode 204

题目描述: Description: Count the number of prime numbers less than a non-negative number, n click to sho...

leetcode 204. Count Primes-素数统计

原题链接:204. Count Primes 按照题目“Show Hint”提示,如果定义一个函数,判断这个数是否是素数,那么效率会很低: public int countPrimes(int...

leetcode 204: Count Primes

问题描述:Description:Count the number of prime numbers less than a non-negative number, n.

LeetCode 204 - Count Primes

一、问题描述Description:Description:Count the number of prime numbers less than a non-negative number, nHi...

LeetCode 204:Count Primes

Description: Count the number of prime numbers less than a non-negative number, n 分析: 题目要求计算小于N的所有...

【LEETCODE】204-Count Primes

Description: Count the number of prime numbers less than a non-negative number, n. 思路: The...

LeetCode笔记:204. Count Primes

寻找小于n的质数个数

Leetcode 204题 Count Primes

题目 :Count PrimesCount the number of prime numbers less than a non-negative number, n.题目分析: 这道题目的意思是写...

Leetcode 204.Count Primes 素性检测

204.Count Primes 问题描述 Count the number of prime numbers less than a non-negative number, n. 翻译:计算小...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)