Jump to content

Proper divisors: Difference between revisions

m
No edit summary
m (→‎{{header|zkl}}: new verson)
Line 4,422:
=={{header|zkl}}==
{{trans|D}}
This is the simple version :
<lang zkl>fcn properDivs(n){ [1.. (n + 1)/2 + 1].filter('wrap(x){ n%x==0 and n!=x }) }</lang>
[1..10].apply(properDivs).println();
This version is MUCH faster (the output isn't ordered however):
<lang zkl>fcn properDivs(n){
if(n==1) return(T);
( pd:=[1..(n).toFloat().sqrt()].filter('wrap(x){ n%x==0 }) )
.pump(pd,'wrap(pd){ if(pd!=1 and (y:=n/pd)!=pd ) y else Void.Skip })
}</lang>
 
<lang zkl>[1..10].apply(properDivs).println();
[1..20_001].apply('wrap(n){ T(properDivs(n).len(),n) })
.reduce(fcn([(a,_)]ab, [(c,_)]cd){ a>c and ab or cd },T(0,0))
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.