Extra primes: Difference between revisions

m
→‎{{header|REXX}}: changed the GENP function.
(Added Sidef)
m (→‎{{header|REXX}}: changed the GENP function.)
Line 1,874:
end /*while*/; return r
/*──────────────────────────────────────────────────────────────────────────────────────*/
genP: #= 9; @.1=2; @.2=3; @.3=5; @.4=7; @.5=11; @.6=13; @.7=17; @.8=19; @.9=23
!.=0; !.2=1; !.3=1; !.5=1; !.7=1; !.11=1; !.13=1; !.17=1; !.19=1; !.23=1
high= max(9 * digits(), iSqrt(hi) ) /*enough primes for sums & primality ÷ */
do j #=29 6; by 2 while sq.#<=high @.# ** 2 /*continuedefine on# withprimes; thedefine next oddsquared prime. */
do j=@.#+4 by 2 while #<=high /*continue on with the next odd prime. */
parse var j '' -1 _ /*obtain the last digit of the J var.*/
if _ _==5 then iterate; if j// 3==0 then iterate /*isJ this÷ integerby a5? multiple ofJ five?÷ by 3?*/
if j // 3 7==0 then iterate; if j//11==0 then iterate /*J "÷ by 7? " J ÷ by " " " " three11? */
if j // 7 ==0 then iterate /* " " " " " " seven? */
if j //11 ==0 then iterate /* " " " " " " eleven?*/
/* [↓] divide by the primes. ___ */
do k=6 to # while k*sq.k<=j /*divide J by other primes ≤ √ J */
if j//@.k == 0 then iterate j /*÷ by prev. prime? ¬prime ___ */
end /*k*/ /* [↑] only divide up to √ J */
#=#+1; @.#= j; @sq.#= j*j; !.j= 1 /*bump number of primes; assign prime#.*/
end /*j*/
hP= @.#; return # /*hP: is the highest prime generated. */</lang>