Anonymous user
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,
if cols>0 then say '───────┼'center("" ,
call facts /*generate a table of needed factorials*/
Eprimes= 0;
$= /*a list of additive primes (so far). */
do j=
do k=1 until fact.k>j /*verify: J-K! for 1≤K!<J are composite*/
z=
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
c= commas(j) /*maybe add some commas to the number. */
$= $ 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>
{{out|output|text= 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
|