Hello!
I am having a hard time with this one. First I got TLE but after adding:
if (m<=1||m>=n||n>=1000000000||n-m>=100000) return 0;
the case moved to wrong anser. However I run the tests and can not figure out what is the issue.
Thank you for your help!
*edit - I adjusted the code a little but now get TLE. It looks like sieve breaks after ~milion operations…
#include <iostream>
#include <cstdlib>
#include <cmath>
using namespace std;
int main()
{
int t=1,cykle;
unsigned int m,n,i,w;
bool *tablica;
cin>>cykle;
if (cykle>10) return 0;
while (cykle>=t)
{
cin >>m>>n;
if (m<1||m>n||n>=1000000000||n-m>=100000) return 0;
tablica=new bool[n+1];
for (i=2;i<=n;i++)
{
tablica[i]=true;
}
for (i=2;i<=n;i++)
{
if (tablica[i])
for (int w=i*i;w<=n;w+=i) tablica[w]=false;
}
for(i=m;i<=n;i++)
{
if (tablica[i]) cout<<i<<endl;
}
t++;
}
delete []tablica;
return 0;
}