0

This is my failed attempt at creating the Sieve of Eratosthenes. Can anyone spot any problems? I just started to learn the STL, but the concept of iterators and the STL in general is really difficult for me.

-The input represents the number of cases. The variable m represents the lower bound and the variable n represents the upper bound.

```
#include <iostream>
#include <list>
#include <iterator>
using namespace std;
int main()
{
int input, m, n;
cin >> input;
for (int i = 0; i < input; i++)
{
cin >> m >> n;
list<int> numbers;
if (m <= 1)
m = 2;
for (int j = m; j <= n; j++)
numbers.push_back(j);
list<int>::iterator it;
for (it = numbers.begin(); it != numbers.end(); ++it)
for (int k = *it; k <= n; k += (*it))
numbers.remove(k);
cout << "Primes between " << m << " and " << n << " are: ";
copy(numbers.begin(),numbers.end(),ostream_iterator<int> (cout, "\n"));
}
return 0;
}
```