#include <stdio.h>
int main(void)
{
long long int i,n1,n2,t,m,j,arr[1000000],c=0,k=0,temp,l;
//printf(“enter test cases\n”);
scanf("%lld",&t); // inputs the test cases
for(i=0;i<t;i++)// till the end of test cases
{
//printf(“enter the numbers\n”);
scanf("%lld",&n1);
scanf("%lld",&n2);
// fill the array with the numbers from the limit
//c = n1;
for(j=1 ; j<=n2 ; j++)
{
arr[j] = j;
//c++;// this is the counter
}
for(j=1 ; j<=n2 ; j++)
{
if(arr[j] == 1 || arr[j] == 0)
{
continue;
}
temp = arr[j];
//printf("\ntemp is %d\n",temp);
for(l=j+1 ; l<=n2 ; l++)
{
if(arr[l] == 0)// escape condition
{
continue;
}
if(arr[l]%temp == 0)// iterating through all the elements and removing the unwanted terms
{
arr[l] = 0; // this is not a prime number
}
}
}
// printing the result
for(j=n1 ; j<=n2 ; j++)
{
if(arr[j] == 0 || arr[j] == 1)
{
continue;
}
else
{
printf("%lld\n",arr[j]);
}
}
}
return 0;
}
My code is working perfectly in my computer but it is “Time limit exceeded”. I had been working on this problem since 3 days.
Can anyone help me with this problem