easy +10 pts

Perfect Number Check

Determine if a positive integer equals the sum of its proper divisors.

A perfect number is a positive integer that is equal to the sum of its proper positive divisors (the divisors excluding the number itself). For example, 6 is perfect because its proper divisors are 1, 2, and 3, and 1 + 2 + 3 = 6. Implement the function `is_perfect(n: int) -> bool` that returns `True` if `n` is a perfect number and `False` otherwise. For `n <= 1`, return `False` because 1 is not perfect (there are no proper divisors) and perfect numbers are defined for positive integers greater than 1. Assumptions: The input will always be an integer (not necessarily positive; handle any integer gracefully).

Constraints

Input is any integer in the range [-10^6, 10^6]. The function should have time complexity O(sqrt(n)) and space complexity O(1).

Example

>>> is_perfect(6)
True
>>> is_perfect(28)
True
>>> is_perfect(12)
False
>>> is_perfect(1)
False
>>> is_perfect(-6)
False
10 points ~15 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Proper divisors include 1 but not the number itself. For any divisor d, also consider n // d to reduce checks.
Iterate only up to the square root of n to find divisors efficiently.
Remember to exclude the number itself from the sum and handle n <= 1.
Sum only divisors strictly less than n; careful when d equals n // d.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.