I have a pn_count() function that is supposed to calculate the number of prime numbers under a given parameter. This function works based on the sieve of atkin but it is calculating wrong values. I dont understand what I am doing wrong, can someone enlighten me in making the function pn_count work?
std::count() doesn't work if its first and second parameters are not iterators into the same sequence. Your pn_count() also has the issue that it's uselessly computing the sieve twice.
1 2 3 4 5 6
longlong inpalprime::pn_count(longlong n)
{
auto p = atkinsieve(n);
longlong primecount= std::count(p.begin(), p.end(), true);
return primecount;
}
longlong inpalprime::pn_count(longlong n)
{
//counts the number of primes less or equal to n
for(std::vector<bool>::size_type it=atkinsieve(n).size()-1; it!=1; it--)
{
if(atkinsieve(n)[it])
{
primecount++;
}
}
return primecount;
}
but if I do it this way it is very inefficient for calculating the number of primes under a given number, does anyone know a way to make this efficient?