Abundant, deficient and perfect number classifications: Difference between revisions

Content added Content deleted
(Add CLU)
(Added XPL0 example.)
Line 5,211: Line 5,211:
There are 4953 abundant numbers between 1 and 20000
There are 4953 abundant numbers between 1 and 20000
There are 4 perfect numbers between 1 and 20000
There are 4 perfect numbers between 1 and 20000
</pre>

=={{header|XPL0}}==
<lang XPL0>int CntD, CntP, CntA, Num, Div, Sum;
[CntD:= 0; CntP:= 0; CntA:= 0;
for Num:= 1 to 20000 do
[Sum:= if Num = 1 then 0 else 1;
for Div:= 2 to Num-1 do
if rem(Num/Div) = 0 then
Sum:= Sum + Div;
case of
Sum < Num: CntD:= CntD+1;
Sum > Num: CntA:= CntA+1
other CntP:= CntP+1;
];
Text(0, "Deficient: "); IntOut(0, CntD); CrLf(0);
Text(0, "Perfect: "); IntOut(0, CntP); CrLf(0);
Text(0, "Abundant: "); IntOut(0, CntA); CrLf(0);
]</lang>

{{out}}
<pre>
Deficient: 15043
Perfect: 4
Abundant: 4953
</pre>
</pre>