Prime1:Logical Error

https://www.codechef.com/problems/PRIME1.

My code is just crashing before entering the values

 #include<iostream>
 #include<cmath>
 #define y 10000000
 using namespace std;

 int main()
 {
   int t,x,j,i=0;
   cin>>t;
   int m,n;
   int primes[y];
   int prime[100000];
   for(i=0;i<=sqrt(y);i++)
      primes[i]=1;
    primes[0]=0;
    primes[1]=0;
    for(i=2;i<=sqrt(y);i++)
    {
        if(primes[i]==1)
        {
            for(j=2;i*j<=sqrt(y);j++)
            primes[i*j]=0;
        }
    }
   while(t--)
   {
   cin>>m >>n;

    i=2;
    while(primes[i]==1)
    {
     x=(m/i)*i;
     for(j=x;j<=n;j=j+i)
     {
         prime[j]=0;
     }
     for(j=m;j<=n;j++)
     {
         if(prime[j]==1)
            cout<<j;
     }
     cout<<"\n";
    i++;
    }
    }

  return 0;

}

In the declaration portion, #define y 10000000, the constant that is declared must be in the range of and int data type. You have to use #define y 100000 or rather use a long long int type of variable in the main() and use it.

But listen primes[y] will again crash as it is beyond the maximum allocated size. So try another solution!

Happy Coding :slight_smile: