题目:若一个数正好等于除自身之外的所有的公约数之和,则称为完数。请打印出1000以内的完数。
分析:用for循环来寻找质因数,然后加起来。
# -*- coding: utf-8 -*-
#By AntInSnow
result = []
for i in range(1,1000):
judge = 0
for j in range(1,i):
if i%j == 0:
judge += j
if judge == i:
result.append(i)
print(result)