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