Cubic special primes: Difference between revisions
Content added Content deleted
(Added Algol W) |
m (→{{header|REXX}}: simplified code, added a foot sep, changed whitespace and comments.) |
||
Line 400: | Line 400: | ||
call genP /*build array of semaphores for primes.*/ |
call genP /*build array of semaphores for primes.*/ |
||
w= 10 /*width of a number in any column. */ |
w= 10 /*width of a number in any column. */ |
||
title= 'the smallest primes < ' commas(hi) " such that the" , |
|||
'difference of successive terma are the smallest cubic numbers' |
'difference of successive terma are the smallest cubic numbers' |
||
if cols>0 then say ' index │'center( |
if cols>0 then say ' index │'center(title, 1 + cols*(w+1) ) /*display the title.*/ |
||
if cols>0 then say '───────┼'center("" |
if cols>0 then say '───────┼'center("" , 1 + cols*(w+1), '─') /* " " sep.*/ |
||
found= 0; idx= 1 /*initialize number of cbp and index.*/ |
|||
op= 1 |
op= 1 |
||
$= /*a list of |
$= /*a list of cubic primes (so far). */ |
||
do j=0 by 0 |
do j=0 by 0 |
||
do k=1 until !.np |
do k=1 until !.np |
||
np= op + k**3 /*find the next cube plus the oldPrime.*/ |
|||
if np>= hi then leave j /*Is newPrime too big? Then quit. */ |
|||
end /*k*/ |
|||
found= found + 1 /*bump number of primes of this type. */ |
|||
op= np /*assign the newPrime to the oldPrime*/ |
op= np /*assign the newPrime to the oldPrime*/ |
||
if cols |
if cols<0 then iterate /*Build the list (to be shown later)? */ |
||
c= commas(np) /*maybe add commas to the number. */ |
c= commas(np) /*maybe add commas to the number. */ |
||
$= $ right(c, max(w, length(c) ) ) /*add a |
$= $ right(c, max(w, length(c) ) ) /*add a cubic prime──►list, allow big#.*/ |
||
if |
if found//cols\==0 then iterate /*have we populated a line of output? */ |
||
say center(idx, 7)'│' substr($, 2); $= /*display what we have so far (cols). */ |
say center(idx, 7)'│' substr($, 2); $= /*display what we have so far (cols). */ |
||
idx= idx + cols /*bump the index count for the output*/ |
idx= idx + cols /*bump the index count for the output*/ |
||
Line 422: | Line 423: | ||
if $\=='' then say center(idx, 7)"│" substr($, 2) /*possible display residual output.*/ |
if $\=='' then say center(idx, 7)"│" substr($, 2) /*possible display residual output.*/ |
||
if cols>0 then say '───────┴'center("" , 1 + cols*(w+1), '─') /*display foot sep. */ |
|||
say |
say |
||
say 'Found ' commas( |
say 'Found ' commas(found) " of " title |
||
exit 0 /*stick a fork in it, we're all done. */ |
exit 0 /*stick a fork in it, we're all done. */ |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
Line 450: | Line 452: | ||
11 │ 2,531 2,539 3,539 3,547 4,547 5,059 10,891 12,619 13,619 13,627 |
11 │ 2,531 2,539 3,539 3,547 4,547 5,059 10,891 12,619 13,619 13,627 |
||
21 │ 13,691 13,907 14,419 |
21 │ 13,691 13,907 14,419 |
||
───────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────────── |
|||
Found 23 of the smallest primes < 15,000 such that the difference of successive terma are the smallest cubic numbers |
Found 23 of the smallest primes < 15,000 such that the difference of successive terma are the smallest cubic numbers |