This is the next development for the Sieve of Eratosthenes algorithm, where all the multiples of 2,3 and 5 are eliminated, which will not take any memory or time.
As my last question Improved Sieve of Eratosthenes I will follow your instructions and study it deeply as soon as I finish my exams.
I wanted to know if there are any specific improvements for this one!
This algorithm generates prime numbers up to a given limit N where it skips the first 10 primes when N>530.
N.B: I can make an infinite number of these developments, as I go higher it gets more and more complicated.
#include <iostream>
int D3SOE(unsigned int n1_m) {
unsigned int n1 = 0, g = 0, z = 0, f1 = 0, f2 = 0, f3 = 0, f4 = 0, f5 = 0, f6 = 0, f7 = 0, f8 = 0, f9 = 0, l = 0, f10 = 0;
int p = 0;
unsigned char* prmLst = new unsigned char[n1_m + 1];
// Initialising the D3SOE array with false values
for (int i = 0; i < n1_m; i++)
prmLst[i] = false;
// The main elimination theorem
for (n1 = 1; n1 <= ceil((8 * (ceil((9 * ceil((2 * (sqrt(((2 * (floor((3 * floor((10 * floor((9 * (n1_m)+1) / 8.0) + 8) / 9.0) + 1) / 2.0)) + 1) / 4.0)) - 0.5) - 1) / 3) - 8) / 10.0)) - 1) / 9); n1++)
{
if (prmLst[n1] != 0)
continue;
z = floor(((3 * floor((10 * floor((9 * (n1)+1) / 8.0) + 8) / 9.0) + 1) / 2.0));
p = ((2 * floor(((3 * floor((10 * floor((9 * (n1)+1) / 8.0) + 8) / 9.0) + 1) / 2.0))) + 1);
f1 = ceil((8 * (ceil((9 * ceil((p - 2) / 3.0) - 8) / 10.0)) - 1) / 9);
f2 = ceil((8 * (ceil((9 * ceil(((7 * p) - 2) / 3.0) - 8) / 10.0)) - 1) / 9);
f3 = ceil((8 * (ceil((9 * ceil(((11 * p) - 2) / 3.0) - 8) / 10.0)) - 1) / 9);
f4 = ceil((8 * (ceil((9 * ceil(((13 * p) - 2) / 3.0) - 8) / 10.0)) - 1) / 9);
f5 = ceil((8 * (ceil((9 * ceil(((17 * p) - 2) / 3.0) - 8) / 10.0)) - 1) / 9);
f6 = ceil((8 * (ceil((9 * ceil(((19 * p) - 2) / 3.0) - 8) / 10.0)) - 1) / 9);
f7 = ceil((8 * (ceil((9 * ceil(((23 * p) - 2) / 3.0) - 8) / 10.0)) - 1) / 9);
f8 = ceil((8 * (ceil((9 * ceil(((29 * p) - 2) / 3.0) - 8) / 10.0)) - 1) / 9);
f9 = ceil((8 * (ceil((9 * ceil(((31 * p) - 2) / 3.0) - 8) / 10.0)) - 1) / 9.0);
l = ceil((8 * (ceil((9 * ceil(((4 * ((z * z) + z)) - 1) / 3.0) - 8) / 10.0)) - 1) / 9);
for (g = l; g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
if ((p - 1) % 30 == 0)
{
for (g = l + (f2 - f1); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
for (g = l + (f3 - f1); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
for (g = l + (f4 - f1); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
for (g = l + (f5 - f1); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
for (g = l + (f6 - f1); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
for (g = l + (f7 - f1); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
for (g = l + (f8 - f1); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
}
else if ((p - 7) % 30 == 0)
{
for (g = l - (f2 - f1); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
for (g = l + (f3 - f2); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
for (g = l + (f4 - f2); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
for (g = l + (f5 - f2); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
for (g = l + (f6 - f2); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
for (g = l + (f7 - f2); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
for (g = l + (f8 - f2); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
}
else if ((p - 11) % 30 == 0)
{
for (g = l - (f3 - f1); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
for (g = l - (f3 - f2); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
for (g = l + (f4 - f3); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
for (g = l + (f5 - f3); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
for (g = l + (f6 - f3); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
for (g = l + (f7 - f3); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
for (g = l + (f8 - f3); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
}
else if ((p - 13) % 30 == 0)
{
for (g = l - (f4 - f1); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
for (g = l - (f4 - f2); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
for (g = l - (f4 - f3); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
for (g = l + (f5 - f4); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
for (g = l + (f6 - f4); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
for (g = l + (f7 - f4); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
for (g = l + (f8 - f4); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
}
else if ((p - 17) % 30 == 0)
{
for (g = l - (f5 - f1); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
for (g = l - (f5 - f2); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
for (g = l - (f5 - f3); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
for (g = l - (f5 - f4); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
for (g = l + (f6 - f5); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
for (g = l + (f7 - f5); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
for (g = l + (f8 - f5); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
}
else if ((p - 19) % 30 == 0)
{
for (g = l - (f6 - f1); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
for (g = l - (f6 - f2); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
for (g = l - (f6 - f3); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
for (g = l - (f6 - f4); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
for (g = l - (f6 - f5); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
for (g = l + (f7 - f6); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
for (g = l + (f8 - f6); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
}
else if ((p - 23) % 30 == 0)
{
for (g = l - (f7 - f1); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
for (g = l - (f7 - f2); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
for (g = l - (f7 - f3); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
for (g = l - (f7 - f4); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
for (g = l - (f7 - f5); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
for (g = l - (f7 - f6); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
for (g = l + (f8 - f7); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
}
else if ((p - 29) % 30 == 0)
{
for (g = l - (f8 - f1); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
for (g = l - (f8 - f2); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
for (g = l - (f8 - f3); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
for (g = l - (f8 - f4); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
for (g = l - (f8 - f5); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
for (g = l - (f8 - f6); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
for (g = l - (f8 - f7); g < n1_m; g += (f9 - f1))
{
prmLst[g] = true;
}
}
}
// printing for loop
for (int n1 = 1; n1 < n1_m; n1++)
if (!prmLst[n1]) {
z = (2 * floor(((3 * floor((10 * floor((9 * (n1)+1) / 8.0) + 8) / 9.0) + 1) / 2.0)) + 1);
std :: cout << z << " ";
}
return 0;
}
// derivation function
int main() {
unsigned int n1_m, N = 0;
std::cout << "\n Enter limit : ";
std::cin >> N;
n1_m = ceil((8 * (ceil((9 * ceil(((N)-2) / 3.0) - 8) / 10.0)) - 1) / 9);
D3SOE(n1_m);
return 0;
}