Skip to content

Instantly share code, notes, and snippets.

@sukeesh
Created May 24, 2020 18:43
Show Gist options
  • Save sukeesh/b9edbcba43f707fbefd9cb49e55d6926 to your computer and use it in GitHub Desktop.
Save sukeesh/b9edbcba43f707fbefd9cb49e55d6926 to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
#include <sstream>
using namespace std;
void generate_sieve(int n){
bool isPrime[n + 1];
memset(isPrime, 1, sizeof(isPrime));
isPrime[0] = 0;
isPrime[1] = 0;
isPrime[2] = 1;
for (int i = 2 ; i <= n ; i ++ ){
if (isPrime[i]) {
for (int j = 2 ; i * j <= n ; j ++ ) {
isPrime[i * j] = 0;
}
}
}
}
int main(int argc, char** argv){
stringstream sn(argv[1]);
int n;
sn >> n;
generate_sieve(n);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment