Untitled

mail@pastecode.io avatar
unknown
python
2 years ago
411 B
3
Indexable
Never
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)