Back to Practice Dashboard
Python BasicsEasy
Perfect number
Learn how to solve the 'Perfect number' problem. This detailed resource details brute force and optimized approaches.
Problem Statement
Easy
Write a function is_perfect(n) that takes a positive integer n and returns True if it is a perfect number, or False otherwise. A perfect number is a number that equals the sum of its proper divisors (all divisors excluding the number itself). For example, 6 = 1 + 2 + 3.
Constraints
- •1 <= n <= 10^6
Examples
Example 1
Input
n = 6
Output
True
Explanation
The proper divisors of 6 are 1, 2, 3. Their sum is 1 + 2 + 3 = 6.
Example 2
Input
n = 28
Output
True
Explanation
The proper divisors of 28 are 1, 2, 4, 7, 14. Their sum is 1 + 2 + 4 + 7 + 14 = 28.
Example 3
Input
n = 12
Output
False
Explanation
The proper divisors of 12 are 1, 2, 3, 4, 6. Their sum is 16, which is not 12.
Need a Hint?
Use simple arithmetic operators (like modulo `%`, division `//`), conditional checks, or loops to inspect number properties.
Edge Cases to Watch
- Empty list or null input variables
- Single item lists/arrays
- Extremely large input bounds causing integer or stack overflow
Ready to Solve?
Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.