Numbers whose count of divisors is prime: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: changed a comment.)
m (→‎{{header|REXX}}: added commas to the output.)
Line 13: Line 13:
call genP /*build array of semaphores for primes.*/
call genP /*build array of semaphores for primes.*/
w= 10 /*W: the maximum width of any column. */
w= 10 /*W: the maximum width of any column. */
title= ' positive integers N whose number of divisors is prime, where N < ' hi
title= ' positive integers N whose number of divisors is prime, where N < ' commas(hi)
say ' index │'center(title, 1 + cols*(w+1) )
say ' index │'center(title, 1 + cols*(w+1) )
say '───────┼'center("" , 1 + cols*(w+1), '─')
say '───────┼'center("" , 1 + cols*(w+1), '─')
Line 24: Line 24:
end
end
finds= finds + 1 /*bump the number of found numbers. */
finds= finds + 1 /*bump the number of found numbers. */
$= $ right(j, w) /*add a positive integer ──► $ list. */
$= $ right( commas(j), w) /*add a positive integer ──► $ list. */
if finds//cols\==0 then iterate /*have we populated a line of output? */
if finds//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). */
Line 33: Line 33:
say '───────┴'center("" , 1 + cols*(w+1), '─')
say '───────┴'center("" , 1 + cols*(w+1), '─')
say
say
say 'Found ' finds title
say 'Found ' commas(finds) title
exit 0 /*stick a fork in it, we're all done. */
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
commas: parse arg ?; do jc=length(?)-3 to 1 by -3; ?=insert(',', ?, jc); end; return ?
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
nDivs: procedure; parse arg x; d= 2; if x==1 then return 1 /*handle special case of 1*/
nDivs: procedure; parse arg x; d= 2; if x==1 then return 1 /*handle special case of 1*/
Line 58: Line 60:
{{out|output|text=&nbsp; when using the default inputs:}}
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
<pre>
index │ positive integers N whose number of divisors is prime, where N < 1000
index │ positive integers N whose number of divisors is prime, where N < 1,000
───────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────
───────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────
1 │ 4 9 16 25 49 64 81 121 169 289
1 │ 4 9 16 25 49 64 81 121 169 289
Line 64: Line 66:
───────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────
───────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────


Found 16 positive integers N whose number of divisors is prime, where N < 1000
Found 16 positive integers N whose number of divisors is prime, where N < 1,000
</pre>
</pre>