题解 | #完全数计算#
完全数计算
http://www.nowcoder.com/practice/7299c12e6abb437c87ad3e712383ff84
if __name__ == "__main__":
while True:
try:
n = int(input().strip())
counter = 0
for i in range(1,n+1):
pf = 0
j = 1
while True:
if i%j == 0:
divisor = i/j # 记录较大的约数divisor
# 若divisor<=约数j,则表示i已经没有其他约数,减少不必要循环
if divisor <= j:
break
pf += j + divisor
j += 1
if pf == 2*i: # 因为循环中当约数为1时,把i本身也加进pf里,所以pf = 2*i。
counter += 1
print(counter)
except:
break