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.

lock icon+16 hidden tests on Submit

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 cases

Case 1

Case 2

Case 3

Input

n = 28

Expected

true