CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
jackfrued

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: jackfrued/Python-100-Days
Path: blob/master/Day01-15/code/Day05/perfect.py
Views: 729
1
"""
2
找出1~9999之间的所有完美数
3
完美数是除自身外其他所有因子的和正好等于这个数本身的数
4
例如: 6 = 1 + 2 + 3, 28 = 1 + 2 + 4 + 7 + 14
5
6
Version: 0.1
7
Author: 骆昊
8
Date: 2018-03-02
9
"""
10
import math
11
12
for num in range(2, 10000):
13
result = 0
14
for factor in range(1, int(math.sqrt(num)) + 1):
15
if num % factor == 0:
16
result += factor
17
if factor > 1 and num // factor != factor:
18
result += num // factor
19
if result == num:
20
print(num)
21
22