编写程序,找到1000以内的完全数
时间: 2023-04-09 10:04:38 浏览: 82
完数课程设计1.doc
以下是一个找到1000以内的完全数的程序:
```python
def is_perfect(num):
divisors = [1]
for i in range(2, int(num**0.5)+1):
if num % i == 0:
divisors.append(i)
if i != num//i:
divisors.append(num//i)
return sum(divisors) == num
perfect_numbers = []
for i in range(2, 1001):
if is_perfect(i):
perfect_numbers.append(i)
print(perfect_numbers)
```
输出结果为:[6, 28, 496]
阅读全文