Sequence: smallest number with exactly n divisors: Difference between revisions
Content added Content deleted
m (→{{header|Sidef}}: added zkl header) |
(→{{header|zkl}}: added code) |
||
Line 323: | Line 323: | ||
=={{header|zkl}}== |
=={{header|zkl}}== |
||
<lang zkl> |
<lang zkl>fcn countDivisors(n) |
||
{ [1.. n.toFloat().sqrt()].reduce('wrap(s,i){ s + (if(0==n%i) 1 + (i!=n/i)) },0) } |
|||
⚫ | |||
fcn A005179w{ |
|||
(1).walker(*).tweak(fcn(n){ |
|||
var N=0,cache=Dictionary(); |
|||
if(cache.find(n)) return(cache.pop(n)); // prune |
|||
while(1){ |
|||
if(n == (d:=countDivisors(N+=1))) return(N); |
|||
if(n<d and not cache.find(d)) cache[d]=N; |
|||
} |
|||
}) |
|||
}</lang> |
|||
⚫ | |||
println("First %d terms of OEIS:A005179:".fmt(N)); |
|||
A005179w().walk(15).concat(" ").println();</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
First 15 terms of OEIS:A005179: |
|||
1 2 4 6 16 12 64 24 36 48 1024 60 4096 192 144 |
|||
</pre> |
</pre> |