Menu
CoddyTech

Perfect Number

A proper divisor of n is a positive divisor smaller than n itself. A perfect number is equal to the sum of its proper divisors: 6 = 1 + 2 + 3. You get a positive integer n. Return true if n is perfect and false otherwise.

Function

isPerfect(n: integer) → boolean
ninteger
the positive integer to test
Returnsboolean
true if n equals the sum of its proper divisors, false otherwise

Constraints

  • 1 ≤ n ≤ 108

Examples

Input
n = 28
Output
true
Explanation
The proper divisors of 28 are 1, 2, 4, 7 and 14. They add up to 28, so 28 is perfect.
challenge icon

Follow-up

Every even perfect number has the form 2^(p-1) × (2^p-1) where 2^p-1 is prime. Can you list all perfect numbers below 10^8 with that formula, without testing each number?

Reset code
def isPerfect(n):
    # Write code here

Test #1

Test #2

Test #3

Argument

n = 28

Expected Output

true