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

3.python算法之完全数

时间:2016-03-21 20:17:12      阅读:311      评论:0      收藏:0      [点我收藏+]

标签:

代码:

#!/usr/bin/env python
# encoding: utf-8
"""
@author: 侠之大者kamil
@file: 3.完全数.py
@time: 2016/3/21 18:02
"""
n = 24
# for i in range(1,n):
#     if n % i ==0:
#         print(i)
def isperfectNumber(n):
    a = 1
    b = n
    s = 0
    while a < b:
        if n % a ==0:
            s += a + b
        a  += 1
        b = n/a
    if a ==b and a*b == n:
        s +=a
    return  s - n == n
for k in range(2,10000):
    if isperfectNumber(k):
        print(k)
def func():
    pass


class Main():
    def __init__(self):
        pass
if __name__ == __main__:
    pass

 

3.python算法之完全数

标签:

原文地址:http://www.cnblogs.com/kamil/p/5303139.html

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