// // #include #include #include using namespace std; vector getPrimes( long nmax ) { vector primeRef ; primeRef.push_back(2); primeRef.push_back(3); for ( long p = 5; p < nmax; p+=2 ) { int index = 0; long t = primeRef[index]; // take only primes to test while (t*t <= p) { // and only those smaller sqrt(p) if ( p % t == 0 ) { // not prime, give up break; } index ++; t = primeRef[index]; } if (t*t > p ) { // found prime primeRef.push_back(p); // append to list } } return primeRef; } int main() { vector primes = getPrimes( 1000000 ); cout << "N-Primes found : " << primes.size() << endl; return 0; }