I am getting a sigsegv error in SPOJ Prime1 problem even after using segmented sieve of eratosthenes

http://www.spoj.com/problems/PRIME1/

```
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int prime[100000];
int myprime[100000];
long long int m,n,i,j,q,s,r,w,p;
int t,range;
cin>>t;
while(t--)
{
r=0;
cin>>m>>n;
range=floor(sqrt(((double)n)));
prime[0]=0;
prime[1]=0;
for(i=2;i<=n;i++)
prime[i]=1;
for(i=2;i<=range;i++)
{
if(prime[i]==1)
{
for(j=2;i*j<=n;j++)
{
prime[i*j]=0;
}
}
}
for(i=2;i<=n;i++)
{
if(prime[i]==1)
{
myprime[r]=i;
r++;
}
}
for(i=0;i<r;i++)
{
w=m/myprime[i];
w=w*myprime[i];
p=myprime[i];
for(s=w;s<=n;s=s+p)
{
if(prime[s]==1)
{
for(q=2;s*q<=n;q++) //possible bug
{
prime[s*q]=0;
}
}
}
}
for(i=m;i<=n;i++)
{
if(prime[i]==1)
{
cout<<i<<"\n";
}
}
cout<<"\n";
}
return 0;
}
```