题解 | #完全数计算#
完全数计算
https://www.nowcoder.com/practice/7299c12e6abb437c87ad3e712383ff84
Python3
def isPerfectNum(n): factor = [] for i in range(1, int(n**0.5) + 1): if i == 1: factor.append(1) continue if n % i == 0: factor.append(i) factor.append(n // i) if sum(factor) == n: return True else: return False while True: try: n = int(input()) res = 0 for i in range(2, n): if isPerfectNum(i): res += 1 print(res) except: break