Perfect numbers: Difference between revisions

Content added Content deleted
No edit summary
Line 926:
False
{6,28,496,8128}</lang>
 
=={{header|MATLAB}}==
Standard algorithm:
<lang MATLAB>function tf = isPerfect(n)
total = 0;
for k = 1:n-1
if ~mod(n, k)
total = total+k;
end
end
tf = total == n;
end</lang>
Somewhat faster:
<lang MATLAB>function tf = isPerfect(n)
total = 0;
k = 1;
while k < n && total <= n
if ~mod(n, k)
total = total+k;
end
k = k+1;
end
tf = total == n;
end</lang>
 
=={{header|Maxima}}==