标签:col pre += else 编程 pen str app 分解
#题目:一个数如果恰好等于它的因子之和,这个数就称为"完数"。例如6=1+2+3.编程找出1000以内的所有完数。 def suoyou(n):#找到所有因子 s = [] for i in range(1,n+1): if n % i ==0: s.append(i) s = s[:len(s)-1] x = 0 # print(‘所有银子‘,s) for i in s: x +=i return x def zhengchu(n):#因式分解 for i in range(2, n + 1): if n % i == 0: k = int(n / i) m.append(i) return zhengchu(k) else: continue if m == []: n = n + 1 else: y = [str(x) for x in m] # print (y) t1 = ‘*‘.join(y) n1 = eval (t1) # print(‘suoyou‘,suoyou(int(X))) if int(n1) == suoyou(int(X)): print (‘%s 为完数‘% X) for n in range(1,1001): # print(‘ha‘,n) X = str(n) m = [] zhengchu(n)
标签:col pre += else 编程 pen str app 分解
原文地址:https://www.cnblogs.com/yelublue/p/8971762.html