Erdős-primes: Difference between revisions

m
→‎{{header|REXX}}: changed some comments, added a foot separator for the output.
(Added Sidef)
m (→‎{{header|REXX}}: changed some comments, added a foot separator for the output.)
Line 646:
call genP n /*generate all primes under N. */
w= 10 /*width of a number in any column. */
if cols>0 then say ' index │'center(" Erdos primes that are < " n, 1 + cols*(w+1) )
if cols>0 then say '───────┼'center("" , 1 + cols*(w+1), '─')
call facts /*generate a table of needed factorials*/
Eprimes= 0; idx= 1 idx= 1 /*initialize # of additive primes & idx*/
$= /*a list of additive primes (so far). */
do j=21 untilfor j>=n#; if \! prime= @.j then iterate /*Is J not a prime? No, then skip it. */
do k=1 until fact.k>j /*verify: J-K! for 1≤K!<J are composite*/
z= jprime - fact.k /*subtract some factorial from a prime.*/
if !.z then iterate j /*Is Z is a prime? Then skip it. */
end /*j*/
 
Eprimes= Eprimes + 1; EprimeL= j /*bump the count of Erdos primes. */
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 #.*/
if Eprimes//cols\==0 then iterate /*have we populated a line of output? */
Line 667:
 
if $\=='' then say center(idx, 7)"│" substr($, 2) /*possible display residual output.*/
if cols>0 then say '───────┴'center("" , 1 + cols*(w+1), '─')
say
say 'found ' commas(Eprimes) " Erdos primes < " commas(n)
Line 688 ⟶ 689:
end /*k*/ /* [↑] only divide up to √ J */
#= # + 1; @.#= j; !.j= 1 /*bump prime count; assign prime & flag*/
end /*j*/; return</lang>
return</lang>
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
Line 697:
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
───────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────
 
found 25 Erdos primes < 2500