Anonymous user
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. */
'difference of successive terma are the smallest quadrat numbers'
if cols>0 then say ' index │'center(
if cols>0 then say '───────┼'center(""
sqp= 0;
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
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 '
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? */
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= 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
|