//Linear Sieve //Finding primes in linear time //Every composite q must have atleast 1 prime factor //Let the smallest prime factor be p //We can say q = p*(i) //When we loop for every i, all primes not exceeding i is already stored in primes //We can pick out each composite exactly once by looping and breaking out when the element divides i #include using namespace std; vector primes; bool check[INT_MAX]; void LinearSieve(int n) { fill(check, check+n, false); for(int i=2;i> n; LinearSieve(n); return 0; }