Anonymous user
Sequence of primes by trial division: Difference between revisions
Sequence of primes by trial division (view source)
Revision as of 20:19, 2 December 2015
, 8 years ago→more optimized: added/changed whitespace and comments.
(→{{header|EchoLisp}}: rmv extra whitespace around subsections) |
m (→more optimized: added/changed whitespace and comments.) |
||
Line 1,011:
if n=='' then n=26 /*Not specified? Then assume default.*/
tell=n>0; n=abs(n) /*N is negative? Then don't display. */
@.1=2; @.2=3; @.3=5; @.4=7; @.5=11; @.6=13; #=5; s=@.#+2
/* [↑] is the number of low primes. */
do p=1 for # while p<=n
if tell then say right(@.p, 9)
!.p=@.p**2 /*also compute the squared value of P. */
end /*p*/ /* [↑] allows faster loop (below). */
/* [↓] N: default lists up to 101 #s.*/
do j=s by 2 while #<n /*
if j//
parse var j '' -1 _ /*obtain the last digit of the J var.*/
if _
if j//
if j//
/* [↓] divide by the primes. ___ */
do k=p to # while !.k<=j /*divide J by other primes ≤ √ J */
if j//@.k==0 then iterate j /*
end /*
#=#+1 /*bump the
@.#=j; !.#=j*j /*define this prime; define its square.*/
if tell then say right(j, 9) /*maybe display this prime ──► terminal*/
end
/* [↓] display number of primes found.*/
say # ' primes found.'
'''output''' is the same as the 1<sup>st</sup> REXX version. <br>
|