Jun 27, 2013 at 2:26pm UTC
OK. I am trying to implement a method that removes all the prime numbers from a vector. They are all numbers from 0 to num, where num in given by the user.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
findVectorPrimes( int num, set< int>& primes)
int squareRoot = sqrt(num);
vector < int> v;
vector< int>::iterator m = v.begin();
while (*m <= squareRoot)
for ( int k = *m; k <= num; k++)
v.erase( (*m) * (k));
There is a separate method that fills the vector.
Its giving me an error and I can't seem to figure it out. Here is the error...
seive.cc:121:35: error: no match for âoperator*â in âv.std::vector<_Tp, _Alloc>::begin<int, std::allocator<int> >().__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator+<int*, std::vector<int> >((* &((__gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type)m.__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator*<int*, std::vector<int> >()))) * kâ
I can't make heads or tails of this. Any assistance would be great. Thanks.
Last edited on
Jun 27, 2013 at 2:29pm UTC
Jun 27, 2013 at 2:32pm UTC
erase expects an iterator as argument but you pass an int.
Jun 27, 2013 at 2:41pm UTC
How would I be able to walk through the vector and remove every number that isn't prime? Could I just use "v.erase(v.at( ( ( *m) * (*k) ) );"?
Jun 27, 2013 at 2:59pm UTC
Its a sieve of arthneus problem, though. I need to find and remove the non-prime spots up to num. Not just remove any number that I would like. :/
Last edited on
Jun 27, 2013 at 3:00pm UTC
Jun 27, 2013 at 3:04pm UTC
why do you use the vector anyway?
can erase the calculated number