Jump to content

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

m
(→‎{{header|zkl}}: added code)
Line 325:
<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();
(1).walker(*).tweak(fcn(n){
if(cache.find(n)) return(cache.pop(n)); // prune
var N=0,cache=Dictionary();
while(1){
if(cache.find(n)) return(cache.pop(n)); // prune
if(n == (d:=countDivisors(N+=1))) return(N);
while(1){
if(n<d ==and not cache.find(d:=countDivisors(N+=1))) return(cache[d]=N);
})
if(n<d and not cache.find(d)) cache[d]=N;
});</lang>
}
})
}</lang>
<lang zkl>N:=15;
println("First %d terms of OEIS:A005179:".fmt(N));
A005179w().walk(15N).concat(" ").println();</lang>
{{out}}
<pre>
First 15 terms of OEIS:A005179:
1 2 4 6 16 12 64 24 36 48 1024 60 4096 192 144
</pre>
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.