Actually, the list of primes is better in this case. Since you dont' know how many primes will be in the range [2,max], so you have no way to reserve the size for the vector. And as the number of primes grow, the vector may have to be reallocated which is a waste of time. The seive can be implemented as an array to type bool instead of unsigned long.
Originally Posted by iMalc
There may be a faster way.
list<unsigned long> prime_gen(unsigned long max)
vector<bool> seive(max, true);
list<unsigned long> primes;
// then iterate over the range [2,max]
for ( unsigned long i = 2; i <= max; ++i)
if( seive[i] )
// then mark off the multiples;
for ( unsigned long j = i; j <= max; j+=i)