题目没有任何输入。
输出2到60之间所有“完数”和“盈数”,并以如下形式输出: E: e1 e2 e3 ......(ei为完数) G: g1 g2 g3 ......(gi为盈数) 其中两个数之间要有空格,行尾不加空格。
无
按题目要求进行输出即可。
def yinshu(n): list1=[] index=n//2 for i in range(1,index+1): if n%i==0: list1.append(i) return list1 list1=[] list2=[] for i in range(2,61): index=yinshu(i) if sum(index)==i: list1.append(str(i)) elif sum(index)>i: list2.append(str(i)) print('E:'+' '+' '.join(list1)) print('G:'+' '+' '.join(list2))
def getFactorSum(num): result = 0 for i in range(num//2,0,-1): if num % i == 0: result += i return result for i in range(2, 61): if getFactorSum(i) == i: e.append(i) elif getFactorSum(i) > i: g.append(i) print('E: ', end="") print(' '.join(map(str, e))) print('G: ', end="") print(' '.join(map(str, g)))
def judge(n):
res = []
for i in range(1, n):
if n % i == 0: res.append(i)
return sum(res) - n
E, G = [], []
for i in range(2, 61):
if judge(i) > 0:
G.append(str(i))
elif judge(i) == 0:
E.append(str(i))
print("E: " + " ".join(E))
print("G: " + " ".join(G))