#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main()
{
cout << "Find all prime numbers <= n, enter n: ";
int n;
cin >> n;
const int NUMBER_PER_LINE = 10;
int count = 0;
int number = 2;
vector<int> primeVector;
int squareRoot = 1;
cout << "The prime numbers are:" << endl;
while (number <= n)
{
bool isPrime = true;
if (squareRoot * squareRoot < number) squareRoot++;
for (int k = 0; k < primeVector.size()
&& primeVector.at(k) <= squareRoot; k++)
{
if (number % primeVector.at(k) == 0)
{
isPrime = false;
break;
}
}
if (isPrime)
{
count++;
primeVector.push_back(number);
if (count % NUMBER_PER_LINE == 0)
{
cout << number << endl;
}
else
cout << number << " ";
}
number++;
}
cout << "\n" << count << " number of primes <= " << n << endl;
return 0;
}