Untitled

 avatar
unknown
python
3 years ago
411 B
6
Indexable
def perfect_number(n):
    powers = {1}
    for i in range(2, int(math.sqrt(n))+1):
        a = i
        while a < n:        
            powers.add(a)
            
    nums = list(powers)
    
    perfect_nums = set()
    for i in range(len(nums)):
        for j in range(len(nums)):
            tmp = nums[i]+nums[j]
            if tmp <= n:
                perfect_nums.add(tmp)
    return len(perfect_nums)
Editor is loading...