Created
October 30, 2016 23:06
-
-
Save firegurafiku/8f1879eb8ddabc01342211e9d7bb9718 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
const int N = 10000000; | |
int main() { | |
// Let the seive be an array (really, std::vector<bool> is not exactly | |
// an array, but that's not important now) of size N with all elements | |
// initially set to 'true' istead of 'false'. | |
std::vector<bool> sieve(N, true); | |
for (int i=2; i <= N / 2; ++i) { | |
if (sieve[i]) { | |
for (int j=i+i; j < N; j += i) | |
sieve[j] = false; | |
} | |
} | |
for (int i=2; i < N; ++i) { | |
if (sieve[i]) | |
std::cout << i << std::endl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment