From 2ccf7a212078941729c21b7024c942e7d14aaf91 Mon Sep 17 00:00:00 2001 From: Griffin-MX <1123306966@qq.com> Date: Wed, 23 Jun 2021 11:53:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E:=20perfect=5Fnew.py=EF=BC=8C?= =?UTF-8?q?=E8=A7=A3=E5=86=B3=E4=BA=86perfect.py=E4=BC=9A=E6=8A=8A1?= =?UTF-8?q?=E5=BD=93=E4=BD=9C=E5=AE=8C=E7=BE=8E=E6=95=B0=E8=BE=93=E5=87=BA?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Day01-15/code/Day05/perfect_new.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Day01-15/code/Day05/perfect_new.py diff --git a/Day01-15/code/Day05/perfect_new.py b/Day01-15/code/Day05/perfect_new.py new file mode 100644 index 0000000..1300e89 --- /dev/null +++ b/Day01-15/code/Day05/perfect_new.py @@ -0,0 +1,20 @@ +""" +找出1~9999之间的所有完美数 +完美数是除自身外其他所有因子的和正好等于这个数本身的数 +例如: 6 = 1 + 2 + 3, 28 = 1 + 2 + 4 + 7 + 14 +Differ: "1" 不是完美数 +Version: 0.2 +Author: Griffin Chen +Date: 2021-6-23 +""" +import math + +for num in range(2, 10000): + result = 0 + for factor in range(1, int(math.sqrt(num)) + 1): + if num % factor == 0: + result += factor + if 1 < factor != num // factor: + result += num // factor + if result == num: + print(num) \ No newline at end of file