Jump to content

Pierpont primes: Difference between revisions

m
→‎{{header|REXX}}: centered the output better.
m (→‎{{header|REXX}}: centered the output better.)
Line 2,001:
do t=1 to -1 by -2; usum= 0; vsum= 0; s= 0 /*T is 1, then -1.*/
#= 0 /*number of Pierpont primes (so far). */
w= 0 /*maximum width of a the Pierpont primeprimes. */
$=; do j=0 until #>=n /*$: the list of the" " " " Pierpont primes.*/
if usum<=s then usum= get(2, 3); if vsum<=s then vsum= get(3, 2)
s= min(vsum, usum); if \isPrime(s) then iterate /*get min; isNot prime? */
#= # + 1; $= $ s /*bump counter; append.*/
w= max(w, length(s) ) /*find max prime width.*/
Line 2,010:
say
if t==-1 then @= '2nd' /*choose word for type.*/
say center(n " Pierpont primes of the " @ ' kind', max(10 *(w+1)-1, 7980), "═")
call show $ /*display the primes. */
end /*t*/
Line 2,021:
end /*j*/; return
/*──────────────────────────────────────────────────────────────────────────────────────*/
isPrime: procedure; parse arg x; if x<2 then return 0 /*not a prime.*/
if wordpos(x, '2 3 5 7')\==0 then return 1 /*it's a prime.*/
if x//2==0 then return 0; if x//3==0 then return 0 /*not a prime.*/
do j=5 by 6 until j*j>x
if x//j==0 then return 0; if x//(j+2)==0 then return 0 /*not a prime.*/
end /*j*/; return 1 /*it's a prime.*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
get: parse arg c1,c2; m=big; do ju=0; pu= c1**ju; if pu+t>s then return min(m, pu+t)
do jv=0; pv= c2**jv; if pv >s then iterate ju
_= pu*pv + t; if _ >s then m= min(_, m)
end /*jv*/
end /*ju*/ /*see the RETURN (above). */</lang>
{{out|output|text=&nbsp; when using the default input:}}
<pre>
═════════════════════50 Pierpont primes of the 1st kind═════════════════════kind══════════════════════
2 3 5 7 13 17 19 37 73 97
109 163 193 257 433 487 577 769 1153 1297
Line 2,042:
839809 995329 1179649 1492993 1769473 1990657 2654209 5038849 5308417 8503057
 
══════════════════════════50 Pierpont primes of the 2nd kind══════════════════════════kind═══════════════════════════
2 3 5 7 11 17 23 31 47 53
71 107 127 191 383 431 647 863 971 1151
Cookies help us deliver our services. By using our services, you agree to our use of cookies.