A perfect number is a number for which the sum of its proper divisors is exactly equal to the number. For example, the sum of the proper divisors of 28 would be 1 + 2 + 4 + 7 + 14 = 28, which means that 28 is a perfect number.
A number n is called deficient if the sum of its proper divisors is less than n and it is called abundant if this sum exceeds n.
As 12 is the smallest abundant number, 1 + 2 + 3 + 4 + 6 = 16, the smallest number that can be written as the sum of two abundant numbers is 24. By mathematical analysis, it can be shown that all integers greater than 28123 can be written as the sum of two abundant numbers. However, this upper limit cannot be reduced any further by analysis even though it is known that the greatest number that cannot be expressed as the sum of two abundant numbers is less than this limit.
Find the sum of all the positive integers which cannot be written as the sum of two abundant numbers.
1. compute the sum of the proper divisors
def sumOfDivision(n):
limit = n/2
i = 2
sum = 1
while i < limit:
if n %i == 0:
limit = n /i
if n /i == i:
sum += i
else:
sum += (i + n/i)
i += 1
return sum
2. finding all the abundant numbers
def abundant():
result = []
for i in range(1,28124):
if sumOfDivision(i) > i:
result.append(i)
return result
3. compute all the sums of the abundant numbers and the sum of those cannot be written as the sum of 2 abundant numbers
def sumOfNonAbundant():
sum = 0
#打表
result = abundant()
flag = [False for i in range(28124)]
l = len(result)
for i in range(l):
for j in range(i,l):
if result[i] + result[j] < 28124:
flag[result[i] + result[j]] = True
for i in range(28124):
if flag[i] == False:
sum += i
return sum
分享到:
相关推荐
projecteuler100:https:projecteuler.net
projecteuler.net 我对 Project Euler 问题的一些解决方案: :
project-euler:多种语言的projecteuler.net问题解决方案
Project的问题的解决方案,因此,看到此处尝试了一种完全不同的方法并返回正确答案应该不会感到震惊。 到目前为止,已经解决了10个问题,但是随着更多解决方案的上传,目录将继续更新。 特定问题的每段代码的名称均...
ProjectEuler题1-16题代码,直接引入Eclipse就可以用
欧拉计划projecteuler.net
project_euler Project Euler 问题的解决方案 ###Problem 1 - 3 和 5 的倍数### 如果我们列出所有 10 以下是 3 或 5 的倍数的自然数,我们得到 3、5、6 和 9。这些倍数的和是 23。求1000 以下所有 3 或 5 的倍数之...
============= project_euler :Info:Profiler工具:作者:Prashant Mital:文档:TBD
ProjectEulerQuestions projecteuler.net 上问题的解决方案
Project-Euler 我使用 C++ 解决 Project Euler 问题 摘自网站: “欧拉计划是一系列具有挑战性的数学/计算机编程问题,需要的不仅仅是数学洞察力来解决。虽然数学可以帮助你找到优雅有效的方法,但解决大多数问题...
project-euler:projecteuler.net问题的解决方案
轻松的文字让数学思想变得自然,读者需要对数学有那么一点兴趣与敬意。不要被书中的公式推导所吓倒,当中所使用的多数为中学知识。
A Most Elegant Equation: Euler’s Formula and the Beauty of Mathematics By 作者: David Stipp ISBN-10 书号: 0465093779 ISBN-13 书号: 9780465093779 出版日期: 2017-11-07 pages 页数: (203) An award-...
ProjectEuler
Project_Euler:用Python解决的Project Euler Math问题
This is a solution the problem 67 of Project Euler website: https://projecteuler.net/archives
我发现的实用程序可解决多个问题,并且不包含破坏代码,可以在euler /路径中找到。 作为历史记录,各个问题路径中的测试案例都包含我对网站做出错误猜测的案例的证据。 其形式为: TEST (Euler, RunProblem) { ...
该软件包包含我针对Euler项目问题的解决方案代码。 源代码包括对所涉及数学的详细说明,以证明程序中的逻辑合理。 此代码仅供“参考”。 您需要事先获得书面许可才能执行以下任何操作:逐字重新发布代码,发布...
#Project Euler 解决方案 一些问题的解决方案。 大多数解决方案都是用Java编写的。