python ProjectEuler问题23回答。来自http://codereview.stackexchange.com/questions/39946/optimizing-solution-

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python ProjectEuler问题23回答。来自http://codereview.stackexchange.com/questions/39946/optimizing-solution-相关的知识,希望对你有一定的参考价值。

def is_abundant(n):
    max_divisor = int(n / 2) + 1
    sum = 0
    for x in range(1, max_divisor):
        if n % x == 0:
            sum += x  
    return sum > n

abundants = list(x for x in range(1, 28123) if is_abundant(x))

sums = 0
for i in range(12, 28123):
    for abundant in abundants:
        if abundant >= i and is_abundant(i + abundant):
            sums += i
print(sums)

以上是关于python ProjectEuler问题23回答。来自http://codereview.stackexchange.com/questions/39946/optimizing-solution-的主要内容,如果未能解决你的问题,请参考以下文章