本文實例講述了Python判斷Abundant Number的方法。分享給大家供大家參考。具體如下:
Abundant Number,中文譯成:盈數(又稱 豐數, 過剩數abundant number)是一種特殊的 自然數,除去它本身以外的一切正約數的和大于它本身。
介紹見百度百科: http://baike.baidu.com/view/1596350.htm
#Checks if a number is abundant or not#An abundant number is the number of which sum of#factors(including itself) is greater than twice the numberdef abundant(n): sum_factors=0 for i in range(1,n+1): if n%i==0: #finds out the factors f=i sum_factors += f if sum_factors>2*n: #condition for abundant number print "This is an Abundant Number!" else: print "This is not an Abundant Number!"
希望本文所述對大家的Python程序設計有所幫助。
新聞熱點
疑難解答