c - SIGSEGV error keeps showing up -


this error keeps on appearing every program try submit on spoj.pl

in given code need find prime numbers between m - n t no. of test cases . problem statement:http://www.spoj.com/problems/prime1/ same error appearing .. can plss tell me why error shows again nd again .. here's code

#include<stdio.h> #include<math.h> #include<stdlib.h>  int main()  {   int t;   scanf("%d",&t);   int *m,*n;   m=(int *)malloc(sizeof(int)*t);   n=(int *)malloc(sizeof(int)*t);   int i=0;   while(i<t)      {           scanf("%d%d",(m+i),(n+i));           i++;       }   i=0;   while(i<t)     {       long long int *list,j,k;       list=((long long int*)malloc(sizeof(long long int)*(n[i]+1)));       list[0]=list[1]=0;       for(j=2;j<=*(n+i);j++)            {                *(list+j)=1;            }       float l=sqrt(*(n+i)+1);       //int l=sqrt(*(n+i)+1);        for(j=2;j<=l;j++)            {                if(*(list+j)==1)                    {                        //printf("\n%ld",j);                        for(k=j*j;k<=*(n+i);k=k+j)                            *(list+k)=0;                     }             }       for(j=m[i];j<=n[i];j++)            {                if(*(list+j)==1)                    {                        printf("\n%ld",j);                     }             }       printf("\n");       free(list);       i++;  } free(m); free(n);   return 0; } 

seems work fine on computer, except warning using %ld (%lld should used). can obtain sigsegv error when putting 0 value n[i]. indicate values used generate error?

edit : testing values "1 888888888 1000000000". computer can't allocate array of such size. asking array of size 1000000001 in memory. amounts 8gb (since long long int 8b, @ least on computer), pretty undoable computer.


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -