# 亲密数if __name__=="__main__":print("3000以内的全部亲密数为:")for a inrange(1,3000):# 穷举3000以内的全部整数b =0i =1while i <=(a//2):# 计算数 a 的各因子,将各因子之和存放到b中if a % i ==0:b += ii +=1n =0# 计算b的各因子,将各因子之和存于 nj =1while j <=(b//2):if b % j ==0:n += jj +=1if n == a and a < b:print("%4d -- %4d \t"%(a, b))
%%time
# 亲密数if __name__=="__main__":print("3000以内的全部亲密数为:")b =0n =0for a inrange(3000):# 穷举30000以内的全部整数# 计算数a的各因子,将各因子之和存放到b中i =1while i <=(a//2):if a % i ==0:b += ii +=1# 计算b的各因子,将各因子之和存于nj =1while j <=(b//2):if b % j ==0:n += jj +=1if n == a and a < b:print("%4d -- %4d \t"%(a, b))
3000以内的全部亲密数为:---------------------------------------------------------------------------KeyboardInterrupt Traceback (most recent call last)File <timed exec>:18, in <module>KeyboardInterrupt: