#include <iostream>
using namespace std;
class sieve_Erastotenes
{
private:
int *first_table;
int size;
public:
sieve_Erastotenes(int x)
{
int i;
size=x;
first_table=new int[size+1];
for(i=1;i<=size;i++)
first_table[i]=i;
}
bool is_True(int x)
{
if(first_table[x]==0)
return true;
else
return false;
}
void Read()
{
int i,j;
i=1;
while(i<size)
{
for(i++;is_True(i);i++);
j=2;
while(i*j<=size)
{
first_table[i*j]=0;
j++;
}
}
}
void Write()
{
int i;
for(i=2;i<=size;i++)
if(!is_True(i))
cout<<first_table[i]<<endl;
}
~sieve_Erastotenes()
{
delete first_table;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
int limit_numbers;
cin>>limit_numbers;
cout<<"The first numbers from 2 to "<<limit_numbers<<endl;
sieve_Erastotenes SE(limit_numbers);
SE.Read();
SE.Write();
getch();
return 0;
}
Brak komentarzy:
Prześlij komentarz