题解 | #完全数计算#
完全数计算
https://www.nowcoder.com/practice/7299c12e6abb437c87ad3e712383ff84
能力有限,谁有更快的方法
n = int(input())
s = 0
while n > 1:
l = '1'
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
if int(n/i) != i:
l += f'+{str(i)}+{str(int(n/i))}'
else:
l += f'+{str(i)}'
if eval(l) == n:
s += 1
n -= 1
print(s)


查看5道真题和解析