Horje
prime numbers less than a given number c++ Code Example
prime numbers less than a given number c++
// This Function returns a vector containing all primes less than n using seive of eratosthenes
vector<long long> primes_less_than(long long n)
{
    vector<long long> ans(0);
    if (n <= 2)
        return ans;
    map<long long, bool> is_prime;
    for(long long i=0; i < n; i++) 
      	is_prime[i] = true;
    is_prime[0] = false;
    is_prime[1] = false;

    for (long long i = 2; i < sqrt(n); i++)
        if (is_prime[i])
            for (long long j = i * i; j < n; j += i)
                is_prime[j] = false;

    for(long long i=0; i < n; i++)
      	if (is_prime[i] == true) 
          	ans.push_back(i);
    return ans;
}




Cpp

Related
how to read a comma delimited file into an array c++ Code Example how to read a comma delimited file into an array c++ Code Example
function overloading in c++ Code Example function overloading in c++ Code Example
c++ hours minutes seconds Code Example c++ hours minutes seconds Code Example
how print fload wiht 3 decimal in c++ Code Example how print fload wiht 3 decimal in c++ Code Example
c++ map iterator Code Example c++ map iterator Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
8