Perfect numbers: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 938: | Line 938: | ||
tf = total == n; |
tf = total == n; |
||
end</lang> |
end</lang> |
||
Faster for large numbers: |
|||
Somewhat faster: |
|||
<lang MATLAB>function tf = isPerfect(n) |
<lang MATLAB>function tf = isPerfect(n) |
||
if n < 2 |
|||
tf = false; |
|||
else |
|||
⚫ | |||
total = 0; |
|||
k = 1; |
|||
upperLimit = ceil(n/2); |
|||
⚫ | |||
if ~mod(n, k) |
|||
⚫ | |||
end |
|||
k = k+1; |
|||
end |
end |
||
tf = total == n; |
|||
end |
end |
||
⚫ | |||
end</lang> |
end</lang> |
||