Click here to Skip to main content
15,880,405 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My challenge is to find the sequence of numbers with the following property that the numbers real divisors are equal to the sum. Real divisors are all positive divisors for the number excluding the number itself.

Example: For N=6 all divisors are [1, 2, 3, 6]
But we exclude number 6 in the set => when N=6 divisors are [1,2,3] and 1+2+3 = 6 and thus satisfies this condition.

What positive numbers below 10000 fits condition?

I found this sequence:
<br />
    [2, 4, 5, 8, 16, 20, 25, 40, 80, 100, 125, 200, 250,500, 625, 1000, 2000, 5000] <br />


What am I doing wrong?
Posted
Updated 8-Dec-14 11:37am
v6

1 solution

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 = (2r-1) ˙ 2r-1 (where r is prime and 2r-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
 
Share this answer
 
v6
Comments
BillWoodruff 9-Dec-14 2:42am    
+5
Andreas Gieriet 9-Dec-14 4:14am    
Thanks for your 5!
Cheers
Andi

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900