Jump to content

Aliquot sequence classifications: Difference between revisions

Line 769:
>
</pre>
 
=={{header|Phix}}==
<lang Phix>function aliquot(atom n)
sequence s = {n}
integer k
if n=0 then return {"terminating",{0}} end if
while length(s)<16
and n<140737488355328 do
n = sum(factors(n,-1))
k = find(n,s)
if k then
if k=1 then
if length(s)=1 then return {"perfect",s}
elsif length(s)=2 then return {"amicable",s}
else return {"sociable",s}
end if
elsif k=length(s) then return {"aspiring",s}
else return {"cyclic",s}
end if
elsif n=0 then return {"terminating",s}
else
s = append(s,n)
end if
end while
return {"non-terminating",s}
end function
 
for i=1 to 10 do
printf(1,"%14d ",i)
? aliquot(i)
end for
 
constant n = {11, 12, 28, 496, 220, 1184, 12496, 1264460, 790, 909, 562, 1064, 1488, 15355717786080}
for i=1 to length(n) do
printf(1,"%14d ",n[i])
? aliquot(n[i])
end for</lang>
{{out}}
<pre>
1 {"terminating",{1}}
2 {"terminating",{2,1}}
3 {"terminating",{3,1}}
4 {"terminating",{4,3,1}}
5 {"terminating",{5,1}}
6 {"perfect",{6}}
7 {"terminating",{7,1}}
8 {"terminating",{8,7,1}}
9 {"terminating",{9,4,3,1}}
10 {"terminating",{10,8,7,1}}
11 {"terminating",{11,1}}
12 {"terminating",{12,16,15,9,4,3,1}}
28 {"perfect",{28}}
496 {"perfect",{496}}
220 {"amicable",{220,284}}
1184 {"amicable",{1184,1210}}
12496 {"sociable",{12496,14288,15472,14536,14264}}
1264460 {"sociable",{1264460,1547860,1727636,1305184}}
790 {"aspiring",{790,650,652,496}}
909 {"aspiring",{909,417,143,25,6}}
562 {"cyclic",{562,284,220}}
1064 {"cyclic",{1064,1336,1184,1210}}
1488 {"non-terminating",{1488,2480,3472,4464,8432,9424,10416,21328,22320,55056,95728,96720,236592,459792,881392,882384}}
15355717786080 {"non-terminating",{1.5355717787e+13,4.4534663602e+13,1.4494008747e+14}}
</pre>
 
 
=={{header|Perl}}==
7,820

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.