for(it1=prime.begin();it1
If you want to erase item and loop, you need do 'it1=prime.begin();' again after erasing. Because of the arrangement.