Search
 
SCRIPT & CODE EXAMPLE
 

CPP

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;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: matplotlib hide numbers on axis 
Cpp :: c++ iterate map 
Cpp :: c++ std::sort 
Cpp :: how to make a loop in c++ 
Cpp :: number of words in c++ files 
Cpp :: ue4 c++ enumaeration 
Cpp :: footnote appears in the middle latex 
Cpp :: min heap and max heap using priority queue 
Cpp :: find in string c++ 
Cpp :: cpp multidimensional vector 
Cpp :: primes in range cpp 
Cpp :: how to store pair in min heap in c++ 
Cpp :: How to find the suarray with maximum sum using divide and conquer 
Cpp :: how to get the first element of a map in c++ 
Cpp :: c++ cast char to string 
Cpp :: check if character in string c++ 
Cpp :: struct and pointer c++ 
Cpp :: joins in mysql use sequelize 
Cpp :: string to uint64_t c++ 
Cpp :: c++ public class syntax 
Cpp :: int main() { 
Cpp :: team fortress 
Cpp :: quick sort c+++ 
Cpp :: how to set a variable to infinity in c++ 
Cpp :: max in c++ 
Cpp :: power function c++ 
Cpp :: c++ reverse string 
Cpp :: cpp string find all occurence 
Cpp :: getline 
Cpp :: c++ preprocessor operations 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =