Erdős-primes: Difference between revisions
Content added Content deleted
(Added Sidef) |
m (→{{header|REXX}}: changed some comments, added a foot separator for the output.) |
||
Line 646: | Line 646: | ||
call genP n /*generate all primes under N. */ |
call genP n /*generate all primes under N. */ |
||
w= 10 /*width of a number in any column. */ |
w= 10 /*width of a number in any column. */ |
||
if cols>0 then say ' index │'center(" Erdos primes that are < " n, |
if cols>0 then say ' index │'center(" Erdos primes that are < " n, 1 + cols*(w+1) ) |
||
if cols>0 then say '───────┼'center("" , |
if cols>0 then say '───────┼'center("" , 1 + cols*(w+1), '─') |
||
call facts /*generate a table of needed factorials*/ |
call facts /*generate a table of needed factorials*/ |
||
Eprimes= 0; |
Eprimes= 0; idx= 1 /*initialize # of additive primes & idx*/ |
||
$= /*a list of additive primes (so far). */ |
$= /*a list of additive primes (so far). */ |
||
do j= |
do j=1 for #; prime= @.j /* */ |
||
do k=1 until fact.k>j /*verify: J-K! for 1≤K!<J are composite*/ |
do k=1 until fact.k>j /*verify: J-K! for 1≤K!<J are composite*/ |
||
z= |
z= prime - fact.k /*subtract some factorial from a prime.*/ |
||
if !.z then iterate j /*Is Z is a prime? Then skip it. */ |
if !.z then iterate j /*Is Z is a prime? Then skip it. */ |
||
end /*j*/ |
end /*j*/ |
||
Eprimes= Eprimes + 1; EprimeL= j /*bump the count of Erdos primes. */ |
Eprimes= Eprimes + 1; EprimeL= j /*bump the count of Erdos primes. */ |
||
if cols |
if cols<0 then iterate /*Build the list (to be shown later)? */ |
||
c= commas(j) /*maybe add some commas to the number. */ |
|||
c= commas(j) |
|||
$= $ right(c, max(w, length(c) ) ) /*add Erdos prime to list, allow big #.*/ |
$= $ right(c, max(w, length(c) ) ) /*add Erdos prime to list, allow big #.*/ |
||
if Eprimes//cols\==0 then iterate /*have we populated a line of output? */ |
if Eprimes//cols\==0 then iterate /*have we populated a line of output? */ |
||
Line 667: | Line 667: | ||
if $\=='' then say center(idx, 7)"│" substr($, 2) /*possible display residual output.*/ |
if $\=='' then say center(idx, 7)"│" substr($, 2) /*possible display residual output.*/ |
||
if cols>0 then say '───────┴'center("" , 1 + cols*(w+1), '─') |
|||
say |
say |
||
say 'found ' commas(Eprimes) " Erdos primes < " commas(n) |
say 'found ' commas(Eprimes) " Erdos primes < " commas(n) |
||
Line 688: | Line 689: | ||
end /*k*/ /* [↑] only divide up to √ J */ |
end /*k*/ /* [↑] only divide up to √ J */ |
||
#= # + 1; @.#= j; !.j= 1 /*bump prime count; assign prime & flag*/ |
#= # + 1; @.#= j; !.j= 1 /*bump prime count; assign prime & flag*/ |
||
end /*j*/ |
end /*j*/; return</lang> |
||
return</lang> |
|||
{{out|output|text= when using the default inputs:}} |
{{out|output|text= when using the default inputs:}} |
||
<pre> |
<pre> |
||
Line 697: | Line 697: | ||
11 │ 769 937 967 1,009 1,201 1,259 1,709 1,831 1,889 2,141 |
11 │ 769 937 967 1,009 1,201 1,259 1,709 1,831 1,889 2,141 |
||
21 │ 2,221 2,309 2,351 2,411 2,437 |
21 │ 2,221 2,309 2,351 2,411 2,437 |
||
───────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────────── |
|||
found 25 Erdos primes < 2500 |
found 25 Erdos primes < 2500 |