Thanks for the reply.
I am trying to solve the PRIME1 problem of SPOJ using Sieve of Eratosthenes. The code works fine for lower integers but shows the following error for long ints -
"Unhandled exception at 0x770d15ee in spoj1.exe: 0xC0000005: Access violation writing location 0x0014010c." Thank you for your help
Here is the code -
#include<stdio.h>
#include<stdlib.h>
int main()
{
int m,n,test,i,k;
long int *arr,p;
scanf("%d",&test);
while(test--)
{
scanf("%d%d", &m, &n);
arr = (long int*)calloc(n-1, sizeof(long int));
if(m==1)
{
m = 2;
}
arr[0] = 2;
for(i=1; i<n-1; i++)
{
arr[i] = arr[i-1] + 1;
//printf("%d\n",arr[i]);
}
for(i=0;i<n-1; i++)
{
if(arr[i] != 0)
{
for(k = arr[i]-2; k<n-1;)
{
k = k + arr[i];
arr[k] = 0;
}
}
}
for(i=0; i<n-1; i++)
{
if(arr[i] != 0 && arr[i] >= m)
{
printf("%d\n",arr[i]);
}
}
printf("\n");
}
free(arr);
return 0;
}