Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
9
Task/Perfect-numbers/MATLAB/perfect-numbers-1.m
Normal file
9
Task/Perfect-numbers/MATLAB/perfect-numbers-1.m
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
function perf = isPerfect(n)
|
||||
total = 0;
|
||||
for k = 1:n-1
|
||||
if ~mod(n, k)
|
||||
total = total+k;
|
||||
end
|
||||
end
|
||||
perf = total == n;
|
||||
end
|
||||
20
Task/Perfect-numbers/MATLAB/perfect-numbers-2.m
Normal file
20
Task/Perfect-numbers/MATLAB/perfect-numbers-2.m
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
function perf = isPerfect(n)
|
||||
if n < 2
|
||||
perf = false;
|
||||
else
|
||||
total = 1;
|
||||
k = 2;
|
||||
quot = n;
|
||||
while k < quot && total <= n
|
||||
if ~mod(n, k)
|
||||
total = total+k;
|
||||
quot = n/k;
|
||||
if quot ~= k
|
||||
total = total+quot;
|
||||
end
|
||||
end
|
||||
k = k+1;
|
||||
end
|
||||
perf = total == n;
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue