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