Jump to content

Perfect numbers: Difference between revisions

no edit summary
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}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.