Created
May 24, 2020 18:43
-
-
Save sukeesh/b9edbcba43f707fbefd9cb49e55d6926 to your computer and use it in GitHub Desktop.
This file contains 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 <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