Optimize TI-BASIC Prime Number
I wrote a program to find all the prime numbers up to N
on my TI-84, however, it is quite slow for any number above, like, 50. Are there any ways to optimize my code?
(I added comments using //
)
Input N
{2}→L2
For(I,3,N,2) // Loop through every odd number up to N starting at 3
1→J
0→H
√(I)→S
While L2(J)≤S and H=0 // checks every previously found prime # less than sqrt(I)
If remainder(I,L2(J))=0
1→H // used to break the loop
J+1→J
End
If H=0 // if no numbers divided evenly, add it to the list
augment(L2, {I})→L2
End
Disp L2
Thanks!
default