Jump to content

Perfect numbers: Difference between revisions

No edit summary
Line 938:
tf = total == n;
end</lang>
Faster for large numbers:
Somewhat faster:
<lang MATLAB>function tf = isPerfect(n)
totalif =n 0;< 2
k tf = 1false;
else
while k < n && total <= n
iftotal ~mod(n,= k)0;
totalk = total+k1;
upperLimit = ceil(n/2);
while k <= nupperLimit && total <= n
if ~mod(n, k)
tf = total == ntotal+k;
end
k = k+1;
end
ktf = k+1total == n;
end
tf = total == n;
end</lang>
 
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.