PRIME1: Getting run time error

please help me to correct this code

#include<stdio.h>
#include<math.h>
#define MAX 100001

char  arr[MAX];
int t;
long long   m,n;
void prime()
{
    int i,j;
    for(i=0;i<=MAX;i++)
        arr[i]=0;
    arr[0]=1,arr[1]=1;
    for(i=2;i<=(int)sqrt(MAX);i++){
        for(j=2;j*i<=MAX;j++)
            arr[i*j]=1;
    }
}
int main()
{
    long long i;
   // long long m,n;
    scanf("%d",&t);
    prime();
    while(t--){
        scanf("%lld %lld",&m,&n);
        for(i=m;i<=n;i++){
            if(arr[i]==0){
                printf("%lld",i);
                printf("\n");
            }
        }
        printf("\n");
    }
    return 0;
}

Try to solve this input - CqpoSL - Online C Compiler & Debugging Tool - Ideone.com

Hint: 99999989 is a prime…

Read the constraints, it says n can be of order 10^9 whereas you have taken MAX to 100001, you are accessing array index out of bounds! By the way, array of size 10^9 is not possible, you’ll get SIGSEGV! You need to change your approach (Look out for segmented prime sieve)

Submission link is prefered - the code is typically formated and linked to problem :wink:

http://www.codechef.com/viewsolution/3791388