def d(i):
k=0 #判断一个数(小于28123)是否写成两个过剩数的和,不能的话返回为真
for m in range(0,len(M)):
for n in range(0,len(M)): #M为小于28123的所有的过剩数
if i==M[m]+M[n]:
return 1
k=1
break
if k==0:
return 0
#求M,所有小于M的过剩数
M=[]
for x in range(1,28123):
s=0
for y in range(1,x):
if x%y==0:
s=s+y
if s>x:
M.append(x)
print M
L=[]
for i in range(1,28123):
if d(i)==0:
L.append(i)
print sum(L)
============================================================================================
别人的
def abun(N):
Q = dict.fromkeys(range(1,N+1), 0)
for q in Q:
for k in [q*n for n in range(1,N/q+1) ]:
if q!=k: Q[k] += q
return [ q for q in Q if Q[q]>q]
N = 20161; A = abun(N); possible = set()
for a in A:
for b in A:
if a+b < N: possible.add( a+b )
else: break
print sum([p for p in range(N) if p not in possible])