include
//#include
using namespace std;
int main(void)
{
int * primeReturn();
void primeSearch(long, long, int *);
int *pArray;
pArray = primeReturn();
int tCount,arrayIndex,fCount=0,tempCount;
long uLimit,lLimit,testCases[21];
cout<<"enter the test cases :";
cin>>tCount;
if(tCount <= 10? tCount : 0)
{
tempCount = tCount;
for(arrayIndex=0;arrayIndex<tempCount*2;)
{
cin>>lLimit>>uLimit;
if((lLimit >= 1) && (uLimit <= 1000000000) && (uLimit-lLimit <= 100000))
{
testCases[arrayIndex] = lLimit;
testCases[(++arrayIndex)++] = uLimit ;
}
else
{
fCount++;
tempCount = tempCount - fCount;
}
}
if(fCount!=0)
tCount= tCount - fCount;
arrayIndex=0;
while(tCount--)
{
lLimit=testCases[arrayIndex];
uLimit=testCases[(++arrayIndex)++];
primeSearch(lLimit,uLimit,pArray);
}
}
//getch();
return 0;
}
int * primeReturn(void)
{
int aa[32000];
int pArray[3432];
for(int i=2;i<=32000;i++)
{
aa[i]=1;
}
for(int i=2;(i*i)<=32000;i++)
{
for(int j=(i*i);j<=32000;j=j+i)
{
aa[j]=0;
}
}
for(int i=2,j=0;i<=32000;i++)
{
if(aa[i]==1)
{
pArray[j++]=i;
}
}
return pArray;
}
void primeSearch(long lLimit, long uLimit, int *pArray)
{
long q,p=0,def;
def=uLimit-lLimit;
long *aa = new long[def + 1];
if(lLimit==1)
lLimit++;
q=lLimit;
for(long i=0;i<=def+1;i++)
{
aa[i]=q++;
}
while((pArray[p]*pArray[p])<=uLimit)
{p++;
}
for(long j=0,k=0;j
{
for(long i=0;i<=def;i++)
{
if((aa[i]!=0) && aa[i]!=pArray[k] && ((aa[i]%pArray[k])== 0))
aa[i]=0;
}
k++;
}cout<<"\n";
for(long k=0;k<=def;k++)
{
if(aa[k]!=0){cout< }
}
Above is my code for prime number generation(code : PRIME1).Here I have used sieve algorithm to get the prime nos.
I have checked all the condition but still I am getting a RUNTIME ERROR (SIGFPE). plz help me...!!