Sequence: smallest number with exactly n divisors: Difference between revisions
Content added Content deleted
(→{{header|REXX}}: flushed out the REXX stub.) |
(→{{header|REXX}}: added optimization (but not really needed for only finding 15 numbers).) |
||
Line 95: | Line 95: | ||
if N=='' | N=="," then N= 15 /*Not specified? Then use the default.*/ |
if N=='' | N=="," then N= 15 /*Not specified? Then use the default.*/ |
||
say '──divisors── ──smallest number with N divisors──' /*display title for the numbers.*/ |
say '──divisors── ──smallest number with N divisors──' /*display title for the numbers.*/ |
||
@.= /*the @ array is used for memoization*/ |
|||
do i=1 for N /*step through a number of divisors. */ |
do i=1 for N /*step through a number of divisors. */ |
||
do j=1 |
do j=1+(i\==1) by 1+(i\==1) /*now, search for a number that ≡ #divs*/ |
||
if @.j==. then iterate /*has this number already been found? */ |
|||
d= #divs(j); if d\==i then iterate /*get # divisors; Is not equal? Skip.*/ |
d= #divs(j); if d\==i then iterate /*get # divisors; Is not equal? Skip.*/ |
||
say center(i, 12) right(j, 19) /*display the #divs and the smallest #.*/ |
say center(i, 12) right(j, 19) /*display the #divs and the smallest #.*/ |
||
@.j=. /*mark as having found #divs for this J*/ |
|||
leave /*found a number, so now get the next I*/ |
leave /*found a number, so now get the next I*/ |
||
end /*j*/ |
end /*j*/ |
||
end /*i*/ |
end /*i*/ |
||
exit /*stick a fork in it, we're all done. */ |
exit /*stick a fork in it, we're all done. */ |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |