Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- #include <vector>
- using namespace std;
- vector<int> sieve(int n) {
- bool prime[n+1];
- memset(prime, true, sizeof(prime));
- vector<int> primes;
- for (int p=2; p*p<=n; p++) {
- if (prime[p] == true) {
- for (int i=p*2; i<=n; i += p)
- prime[i] = false;
- }
- }
- for (int p=2; p<=n; p++) {
- if (prime[p]) {
- primes.push_back(p);
- }
- }
- }
- int main() {
- vector<int> ans = sieve(100000);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement