I have independently found a quite fast way. I think it has been already posted in that link thornahawk posted.

For a list of primes up to N, you do this:

```
Input N
SetUpEditor L1
{2,3->L1
For(P,3,N,2
For(Q,2,dim(L1
If not(fPart(P/L1(Q
9+dim(L1->Q
End
If Q-3<dim(L1
P->L1(1+dim(L1
End
```

Explaining rly fast (all the operations are to occur exclusively with integer values): through the Fundamental Theorem of Arithmetics, you have that any integer greater than 1 is itself a prime number or a product of prime numbers, and that a number described by the second situation is a non-prime number, or a composite number.

First of all, step at finding possible values of P is 2, as there are no even primes.

Store 2 and 3 as prime numbers to L1.

Second, follow my idea (for this mathematical concept, p will denote our P to be checked):

Let A be the set of prime numbers inferior to p (for each time you check if P is prime, you'll always have this set as L1).

p is composite if ∃a∈A: fpart(p/a)=0

i.e.: if p is divisible by a prime a, there are two numbers (a and p/a) whose product is p

a*(p/a)=a,

a -> some prime number

p/a -> some prime number, or a composite number

If the previous statement is true, 9+dim(L1) is stored to Q, and, as the program reaches the For(N,2,dim(L1)) line, it will exit the loop because Q is higher than dim(L1). In this case, any number from 4 to infinity could be stored, but i chose the highest single-digit number so that it would save memory and be big enough not to be close to 1 and 2.

Remember: Q is equal to 9+dim(L1) if P is composite.

So, if Q-3<dim(L1) (that is, Q was not altered to skip the loop, meaning the loop went all the way through the prime numbers list), then P is not composite, and therefore P is prime, so you store it as the last element of L1.

Cons:

Slower than the original algorithm when checking lower numbers (maybe up to 10 or 20), as recalling elements from a list is a bit slower.

Harder to understand at first glance.

Pros:

Really faster for higher numbers, meaning it does not slow down as fast as the originally proposed algorithm.

It is smaller than thornahawk's final proposal at Cemetech, and mine only uses For( loops. As being smaller and only using For( loops makes it generally faster, i suppose it is faster.

Cleaver algorithm, as it uses the Fundamental Theorem of Arithmetics to make it faster, and make you look cleaver when showing your algorithm to someone xD

I have not tested either of the algorithms, so answer me if you find any errors.