These numbers have a name:
Perfect Numbers. See
Perfect Number[
^].
Calculate for each
Marsenne Prime[
^] P the corresponding perfect number N: N = P*(P+1)/2 = (2
r-1) ˙ 2
r-1 (where r is prime and 2
r-1 is prime = Marsenne Prime).
P = 3 N = 3*4/2 = 6
P = 7 N = 7*8/2 = 28
P = 31 N = 31*32/2 = 496
P = 127 N = 127*128/2 = 8128
What is your formula? You calculate the divisors of 10000 only. If you do the brute force approach, do the following (I leave the translation from pseudo code to C# as exercise):
foreach n in 2...10000 loop
if (IsPerfectNumber(n)) then
Write(n)
end if
end loop
function IsPerfectNumber(n) return bool
begin
return SumOfAllDividers(n) == n + n
end function
function SumOfAllDividers(n) return integer
begin
sum = 0
sentry = floor(sqrt(n))
foreach d in 1...sentry loop
if (n % d == 0) then
sum += d
sum += n/d
end if
end loop
return sum
end function
Cheers
Andi