But just to be certain, i dont have to 'cheat' to solve the problem do i? I dont have to have the primes precompiled do i?
and heres my latest attempt, of course its WAY slow. ( i am seeing that even just checking integer by integer if it is prime would maybe be faster..still not fast enough, i might just scrap this attempt.)
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
void countPrimes(const int& start,const int& end)
{
int bound = (int)floor(sqrt((double)end));
vector<int> *p = new vector<int>;
p->push_back(2);
for ( int i = 3 ; i <= end; i+=2)
{
p->push_back(i);
}
//eratosthenes
for( int i = 1; i < p -> size(); ++i)
{
if(p->at(i) > bound)
{
break;
}
for(int j = i+1; j < p -> size(); )
{
if(p->at(j) % p->at(i) == 0)
p->erase(p->begin()+j);
else
++j;
}
}
for(int i= 0; i < p->size();++i)
if(p->at(i) >= start)
cout << p->at(i) << endl;
cout << endl;
}
int main()
{
int trials;
cin >> trials;
int *nums = new int[trials*2];
for(int i = 0; i < trials*2; ++i)
{
cin >> nums[i];
}
for(int i=0;i<trials*2;i+=2)
{
countPrimes(nums[i],nums[i+1]);
}
}