Skip to content
DeepForgeby svx
All problems
EasyAlgorithmsal-054

Perfect Number

Problem

Return True if n is a perfect number, meaning n equals the sum of its proper divisors, and False otherwise.

Sum divisor pairs up to the square root, starting from 1, and compare the total with n. Numbers less than or equal to 1 are not perfect.

Hint

Every divisor below the square root has a partner above it; add both while avoiding double counting a perfect square.

Test cases

case 1
in: [6]
expected: true
case 2
in: [28]
expected: true
case 3
in: [12]
expected: false
case 4
in: [1]
expected: false
case 5
in: [496]
expected: true
Starter codePython
def is_perfect_number(n):
    # Your code here
    pass

5 test cases · run your code against them in the editor