找到与起始编号相加的数字的正数除数 [英] Find positive divisors for number that adds up to starting number

查看:92
本文介绍了找到与起始编号相加的数字的正数除数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的挑战是找到具有以下属性的数字序列,数字实数除数等于和。真正的除数都是除数字本身之外的正数除数。



示例:对于N = 6,所有除数都是[1,2,3,6]

但我们排除了集合中的数字6 =>当N = 6除数为[1,2,3]且1 + 2 + 3 = 6时因此满足此条件。



10000以下的正数适合条件?



我发现这个序列:

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?

推荐答案

这些数字有一个名称:完美数字。请参见完美数字 [ ^ ]。

计算每个 Marsenne Prime [ ^ ] P相应的完整数字N:N = P *(P + 1)/ 2 =(2 r -1)˙2 r-1 (其中r是素数,2 r -1是prime = Marsenne Prime)。

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





你的配方是什么?您只计算10000的除数。如果你采用蛮力方法,请执行以下操作(我将伪代码转换为C#作为练习):





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





干杯

Andi



Cheers
Andi


这篇关于找到与起始编号相加的数字的正数除数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆