Quadrat special primes: Difference between revisions

m
→‎{{header|REXX}}: added/changed comments and whitespace, added a foot separator.
(Added XPL0 example.)
m (→‎{{header|REXX}}: added/changed comments and whitespace, added a foot separator.)
Line 471:
call genP /*build array of semaphores for primes.*/
w= 10 /*width of a number in any column. */
@sqptitle= 'the smallest primes < ' commas(hi) " such that the" ,
'difference of successive terma are the smallest quadrat numbers'
if cols>0 then say ' index │'center(@sqp title, 1 + cols*(w+1) )
if cols>0 then say '───────┼'center("" , 1 + cols*(w+1), '─')
sqp= 0; idx= 1 idx= 1 /*initialize number of sqp and index.*/
op= 1
$= /*a list of nice primes (so far). */
Line 484:
sqp= sqp + 1 /*bump the number of sqp's. */
op= np /*assign the newPrime to the oldPrime*/
if cols==<0 then iterate /*Build the list (to be shown later)? */
c= commas(np) /*maybe add commas to the number. */
$= $ right(c, max(w, length(c) ) ) /*add a nice prime ──► list, allow big#*/
Line 493:
 
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(sqp) " of " @sqp title
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
Line 508 ⟶ 509:
if j// 3==0 then iterate /*" " " 3? */
if j// 7==0 then iterate /*" " " 7? */
/* [↑] the above five lines saves time*/
do k=5 while s.k<=j /* [↓] divide by the known odd primes.*/
if j // @.k == 0 then iterate j /*Is J ÷ X? Then not prime. ___ */
end /*k*/ /* [↑] only process numbers ≤ √ J */
#= #+1; @.#= j; s.#= j*j; !.j= 1 /*bump # of Ps; assign next P; P²; P# */
end /*j*/; return</lang>
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
Line 523:
31 │ 7,247 7,283 7,607 7,643 8,219 8,363 10,667 11,243 11,279 11,423
41 │ 12,323 12,647 12,791 13,367 13,691 14,591 14,627 14,771 15,671
───────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────
 
Found 49 of the smallest primes < 16,000 such that the difference of successive terma are the smallest quadrat numbers