Sequence: nth number with exactly n divisors: Difference between revisions

Content added Content deleted
m (→‎more optimization: added whitespace, added/changed comments, elided a superfluous semicolon.)
m (→‎little optimization: optimized the K do loop, increased number of decimal digit precision.)
Line 1,009: Line 1,009:
parse arg N . /*obtain optional argument from the CL.*/
parse arg N . /*obtain optional argument from the CL.*/
if N=='' | N=="," then N= 15 /*Not specified? Then use the default.*/
if N=='' | N=="," then N= 15 /*Not specified? Then use the default.*/
if N>=50 then numeric digits 10 /*use more decimal digits for large N. */
w= 50 /*W: width of the 2nd column of output*/
w= 50 /*W: width of the 2nd column of output*/
say '─divisors─' center("the Nth number with exactly N divisors", w, '─') /*title.*/
say '─divisors─' center("the Nth number with exactly N divisors", w, '─') /*title.*/
Line 1,049: Line 1,050:
else do; #= 3; y= x%2; end /*Even? " " " " 3.*/
else do; #= 3; y= x%2; end /*Even? " " " " 3.*/
/* [↑] start with known num of Pdivs.*/
/* [↑] start with known num of Pdivs.*/
do k=3 for x%2-3 by 1+odd while k<y /*for odd numbers, skip evens.*/
do k=3 by 1+odd while k<y /*when doing odd numbers, skip evens. */
if x//k==0 then do /*if no remainder, then found a divisor*/
if x//k==0 then do /*if no remainder, then found a divisor*/
#=#+2; y=x%k /*bump # Pdivs, calculate limit Y. */
#=#+2; y=x%k /*bump # Pdivs, calculate limit Y. */