Sequence: smallest number with exactly n divisors: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
(Added PROMAL) |
||
Line 1,475: | Line 1,475: | ||
2^k*3^4*p (made up rule):4 |
2^k*3^4*p (made up rule):4 |
||
1440 (complete fudge):1 |
1440 (complete fudge):1 |
||
</pre> |
|||
=={{header|PROMAL}}== |
|||
Builds a table of divisor counts wihout division. |
|||
<syntaxhighlight lang="promal"> |
|||
;;; Find the smallest number with n divisors, n in 1..15 |
|||
PROGRAM SmallestN |
|||
INCLUDE LIBRARY |
|||
CON WORD maxDivisors = 15 ; number of sequence elements to find |
|||
CON WORD maxNUmber = 6000 ; maximum number we will consider |
|||
WORD dc [ maxNumber + 1 ] |
|||
WORD firstWithDivisors [ maxDivisors + 1 ] |
|||
WORD found |
|||
WORD divisors |
|||
WORD d |
|||
WORD n |
|||
WORD j |
|||
BEGIN |
|||
; compute a table of divisor counts |
|||
FOR n = 1 TO maxNumber |
|||
dc[ n ] = 0 |
|||
FOR n = 1 TO maxNumber |
|||
j = n |
|||
WHILE j <= maxNumber |
|||
dc[ j ] = dc[ j ] + 1 |
|||
j = j + n |
|||
; find the first number wih the required divisor counts |
|||
FOR n = 0 TO maxDivisors |
|||
firstWithDivisors[ n ] = 0 |
|||
found = 0 |
|||
n = 0 |
|||
WHILE found < maxDivisors |
|||
n = n + 1 |
|||
divisors = dc[ n ] |
|||
IF divisors <= maxDivisors |
|||
IF firstWithDivisors[ divisors ] = 0 |
|||
; first number with this number of divisors |
|||
found = found + 1 |
|||
firstWithDivisors[ divisors ] = n |
|||
FOR d = 1 TO maxDivisors |
|||
OUTPUT " #W", firstWithDivisors[ d ] |
|||
END |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
1 2 4 6 16 12 64 24 36 48 1024 60 4096 192 144 |
|||
</pre> |
</pre> |
||