Search
 
SCRIPT & CODE EXAMPLE
 

CPP

sieve cpp

#include <iostream>
#include <vector>
#include <algorithm>
#include <bitset>

#define N 1000000	//N is the Range (0..N)

bitset < N+1 > numbers;
vector < int > primes;

void sieve(){
    numbers.set();
    numbers[1] = 0;

    for (int i = 2; i < N; i++){
        if (numbers[i] == 1){
            cout<<i<<endl;
            primes.push_back(i);
            for (int j = i*i; j<=N; j+=i)
                numbers[j] = 0;
        }
    }
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: sieve of eratosthenes algorithm in c++ 
Cpp :: segmented sieve of Eratosthenes in cpp 
Cpp :: armstrong number in cpp 
Cpp :: C++ std::string find and replace 
Cpp :: how to scan array in c++ 
Cpp :: get window position 
Cpp :: bitwise count total set bits 
Cpp :: how to easily trim a str in c++ 
Cpp :: matrix transpose in c++ 
Cpp :: vector size for loop 
Cpp :: inbuilt function to convert decimal to binary in c++ 
Cpp :: remove decimal c++ 
Cpp :: c++ remove numbers from vector if larger than n 
Cpp :: how to split a string in c++ 
Cpp :: clear qlayout 
Cpp :: c++ cout format 
Cpp :: powershell get uptime remote computer 
Cpp :: iterate over vector in c++ 
Cpp :: initialize string with length c++ 
Cpp :: change colour of output to terminal c++ 
Cpp :: inline in class in C++ 
Cpp :: pragma cpp 
Cpp :: ++i and i++ 
Cpp :: temperature conversion in c++ 
Cpp :: c++ char array size 
Cpp :: function overloading in c++ 
Cpp :: C++ continue with for loop 
Cpp :: SUMOFPROD2 codechef solution 
Cpp :: strring length in c++ 
Cpp :: initialize a vector to 0 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =