Prime Sieve of Eratosthenes.cpp

Prime Sieve of Eratosthenes

This version of the sieve stores all the numbers of sieve. But uses slightly more memory as opposed to a bit array of size n.
 * 1) include
 * 2) include

/*primes is a list of primes, n is all the primes you want to generate.. from 2 to n*/ void genPrimes(vector &primes,int n){ int root; bool found; for(int i=2;i<=n;i++){ root=int(sqrt(i))+1;   /*remember the square root*/ found=false;           /*prime found?*/ for(int j=0;j<primes.size&& primes[j]<root;j++){ if(i%primes[j]==0){found=true;break;} /*this is not prime*/ }		if(!found)primes.push_back(i); /*this is a prime*/ } }