> For the complete documentation index, see [llms.txt](https://coding-9.gitbook.io/untitled/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://coding-9.gitbook.io/untitled/insights-and-new-learnings/seive-of-erathostenis.md).

# Seive of Erathostenis

## Learnings

\
To generate Primes in a range from 1 to N\
\
Start from 2 and mark all Divisors of 2 as false\
So on for 3 and continue

## Intuition

```
    vector<int> seive(int n){
        vector<int> prime(n+1, 1);
        prime[0] = 0;
        prime[1] = 0;

        for(int p=2; p*p<=n; p++){
            if(prime[p] == true){
                for(int i=p*p; i<=n; i+=p){
                    prime[i] = false;
                }
            }
        }
        
        // Ones for all Those are prime Till N

        return prime;
    }
```

### Links

<https://leetcode.com/problems/find-the-count-of-numbers-which-are-not-special/>
