27na 7alena l mas2ala de by Sieve bs gt run time error
l moshkela ba2a ana ma3rafsh ya3ny a run time error da ya3ny moshkelto feen?
+ 3'aleban kda fe 7aga ana msh fahmaha fel mas2ala ya3ny hwa haybda2 y3ml display mnen 3alshan fel UVa kateb haybda2 mn l center of the list 27na tawasalna 2no yo2sod l interval nafsaha 2ly hada5alha msh yo2sod l list bta3t l prime numbers ya3ny bs l moshkela fel display haybda2 mnen ya3ny?
this is the code:
- Code: Select all
#include <iostream>
#include <cmath>
#define LIMIT 1001
using namespace std;
bool prime[LIMIT];
void Sieve()
{
int i, j;
for(i=0; i<LIMIT; i++)
prime[i] = 1;
for(i=2; i<sqrtl(LIMIT) + 1; i++)
if(prime[i])
{
for(j = i*i ; j < LIMIT ; j += i)
prime[j] = 0;
}
}
int main ()
{
Sieve();
int Number,x,y , count;
while (cin >> Number >> x)
{
count = 0;
cout<<Number<<" "<<x<<": ";
if(x != Number)
{
if(Number % 2 == 1)
{
y = (x*2)-1;
for(int i = y+1 ; ; i++)
{
if(count == y)
break;
if(prime[i])
{
cout<<i<<" ";
count++;
}
}
cout<<endl;
}
else
{
y = (x*2);
for(int i = y-1 ; ; i++)
{
if(count == y )
break;
if(prime[i])
{
cout<<i<<" ";
count ++;
}
}
cout<<endl;
}
}
else
{
for(int i = 1 ; i < Number ; i++)
{
if(prime[i])
cout<<i<<" ";
}
cout<<endl;
}
cout<<endl;
}
return 0;
}
thnx for ur help in advance
