#include <iostream>
#include <iomanip>
#include <cstring>
using namespace std;
bool isPrime(int n)
{
if (n==2)
return 1;
for (int i=2; i * i <= n;++i)
{
if (n%i == 0)
return 0;
}
return 1;
}
int main(int argc, char const *argv[])
{
int end;
cout << "Please enter the range" << endl;
cin >> end;
bool *p = new bool[end + 1];
memset(p, 1, end + 1);
for (int i = 2; i <= end; ++i)
{
if (p[i] && isPrime(i))
{
for (int j = 2; j * i <= end; ++j)
{
p[j * i] = 0;
}
}
}
cout << endl << "PrimeTable is followed : \n" ;
int number = 0;
for (int i = 2; i <= end; ++i)
{
if (p[i])
{
cout << setw(5) << i;
++number;
if (number && !((number % 8)))
cout << endl;
else if (number)
cout << " ";
}
}
delete[]p;
p = NULL;
return 0;
}