Jump to content

Summarize primes: Difference between revisions

m
→‎{{header|REXX}}: simplified program, added/changed whitespace and comments.
m (added whitespace and a comma.)
m (→‎{{header|REXX}}: simplified program, added/changed whitespace and comments.)
Line 1,030:
@.1=2; @.2=3; @.3=5; @.4=7; @.5=11 /*define some low primes. */
!.2=1; !.3=1; !.5=1; !.7=1; !.11=1 /* " " " " flags. */
#=5; ssq.#= @.# **2 /*number of primes so far; prime². */
/* [↓] generate more primes ≤ high.*/
do j=@.#+2 by 2 until @.#>=hi & @.#>sP /*find odd primes where P≥hi and P>sP.*/
parse var j '' -1 _; if _==5 then iterate /*J divisible÷ by 5? (right digdigit)*/
if j//3==0 then iterate; if j// 37==0 then iterate /*"J ÷ " "by 3?; J ÷ by 7? */
do k=5 while sq.k<=j if j// 7==0 then iterate /*" " " 7? [↓] divide by the known odd primes.*/
do k=5 while s.k<=j /* [↓] divide by the known odd primes.*/
if j // @.k == 0 then iterate j /*Is J ÷ X? Then not prime. ___ */
end /*k*/ /* [↑] only process numbers ≤ √ J */
#= #+1; @.#= j; ssq.#= j*j; !.j= 1 /*bump # of Ps; assign next P; P square; P# */
if @.#<hi then sP= sP + @.# /*maybe add this prime to sum─of─primes*/
end /*j*/; return</lang>
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
Cookies help us deliver our services. By using our services, you agree to our use of cookies.