码迷,mamicode.com
首页 > 编程语言 > 详细

python 函数 亲密数对

时间:2021-05-24 02:48:19      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:rss   因子   tor   int   print   span   factor   def   python 函数   

"""
亲密数对(3000以内) 3 - 3000
整体思路:
分别计算A:3,4,5,6,他们因子 之和 B
对因子和B 计算 因子和C
如果 A==C,说明A和B是亲密数对

如果整数A的全部因子(包括1,不包括A本身)之和等于B;
且整数B的全部因子(包括1,不包括B本身)之和(C)等于A,
则将整数A和B称为亲密数。
"""
##计算 n 的因子 之和
def factorsSum(n):
sum = 0
i = 1
while i <= n - 1:
if n % i == 0:
sum += i
i += 1
return sum

for a in range(3,3000):
b = factorsSum(a)
c = factorsSum(b)
if(a == c and a != b):
print("%d 和 %d"%(a,b))

python 函数 亲密数对

标签:rss   因子   tor   int   print   span   factor   def   python 函数   

原文地址:https://www.cnblogs.com/ZhaoBa/p/14747147.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!