题解 | #完全数计算#
完全数计算
http://www.nowcoder.com/practice/7299c12e6abb437c87ad3e712383ff84
n = int(input()) start = 1 count = 0 out = []
which = []
for i in range(2, n + 1): while True: if i % start == 0: out.append(start) if i == start: start = 1 #,重置start,重新计算 break start += 1 if sum(out[0:-1]) == out[-1]: count += 1 # which.append(out[-1]) #输出完全数 out.clear() #清空out,重新计算 print(count)
查看18道真题和解析