Erdős-primes: Difference between revisions

m
→‎{{header|REXX}}: added code to support showing the largetst Erdos prime < one million.
m (added highest < 1,000,000 comment)
m (→‎{{header|REXX}}: added code to support showing the largetst Erdos prime < one million.)
Line 275:
if n=='' | n=="," then n= 2500 /*Not specified? Then assume default.*/
if cols=='' | cols=="," then cols= 10 /* " " " " " */
call genPnn= n; n= abs(n) /*generate all primes under N. <0: shows highest Erdos prime< │N│ */
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) )
Line 282 ⟶ 283:
Eprimes= 0; idx= 1 /*initialize # of additive primes & idx*/
$= /*a list of additive primes (so far). */
do j=2 until j>=n; if \!.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= j - 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)
$= $ 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? */
say center(idx, 7)'│' substr($, 2); $= /*display what we have so far (cols). */
idx= idx + cols /*bump the index count for the output*/
end /*j*/
 
if $\=='' then say center(idx, 7)"│" substr($, 2) /*possible display residual output.*/
say
say 'found ' commas(Eprimes ) " Erdos primes < " commas(n)
say
if nn<0 then say commas(EprimeL) ' is the ' commas(Eprimes)th(Eprimes) " Erdos prime."
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
commas: parse arg ?; do jc=length(?)-3 to 1 by -3; ?=insert(',', ?, jc); end; return ?
facts: arg x; fact.=1; do x=2 until fact.x>n1e9; p= x-1; fact.x= x*fact.p; end; return
th: parse arg th; return word('th st nd rd', 1+(th//10) *(th//100%10\==1) *(th//10<4))
/*──────────────────────────────────────────────────────────────────────────────────────*/
genP: parse arg n; @.=.; @.1=2; @.2=3; @.3=5; @.4=7; @.5=11; @.6=13; @.7=17; #= 7
Line 327 ⟶ 331:
 
found 25 Erdos primes < 2500
</pre>
 
{{out|output|text=&nbsp; when using the inputs if: &nbsp; &nbsp; <tt 1000000 &nbsp; 0 </tt>}}
<pre>
found 7,875 Erdos primes < 1,000,000
 
999,721 is the 7,875th Erdos prime.
</pre>