Proper divisors: Difference between revisions

Line 885:
 
=={{header|Phix}}==
The factors routine is an auto-include. The actual implementation of it, from builtins\pfactors.e is
<lang Phix>global function factors(atom n, integer include1=0)
-- returns a list of all integer factors of n
-- if include1 is 0 (the default), result does not contain either 1 or n
-- if include1 is 1, and n>1, the result contains 1 and n
-- if include1 is -1, and n>1, the result contains 1 but not n
sequence lfactors = {}, hfactors = {}
atom hfactor
integer p = 2,
lim = floor(sqrt(n))
 
if n!=1 and include1!=0 then
lfactors = {1}
if include1=1 then
hfactors = {n}
end if
end if
while p<=lim do
if remainder(n,p)=0 then
lfactors = append(lfactors,p)
hfactor = n/p
if hfactor=p then exit end if
hfactors = prepend(hfactors,hfactor)
end if
p += 1
end while
return lfactors & hfactors
end function</lang>
The compiler knows where to find that, so the main program is just:
<lang Phix>for i=1 to 10 do
?{i,factors(i,-1)}
Line 921 ⟶ 950:
79 divisors:{15120,18480}
</pre>
 
 
=={{header|PicoLisp}}==
7,818

edits