I'm trying to solve the 2nd problem prime generator. My solution works (no check yet) but I tought it might be a good idea to skip even numbers from (m,n) interval. And thats the point where it stops working properly. I can't guess by myself whats wrong since 2 days. Please help.
is_prime(a) checks if number is prime and returns bool.
int main(void)
{
int t;
std::cin >> t;
if (t>10)
{
return 0;
}
for (int k=1; k<=t; k++)
{
int m,n;
std::cin >> m >> n;
if(m%2==0) //without this works fine
{ //
m=m+1; // there is no output at all if I use theese lines
} //
for(int j=m; j<=n; j+=2) //without m checked(odd/even), the j increase should be set to 1
{
bool status=is_prime(j);
if(status)
{
std::cout << j << "\n";
}
}
std::cout << "\n";
}
return 0;
}