A perfect number is a positive integer that is equal to the sum of its proper divisors (divisors excluding the number itself).
Your task is to create a method that checks if a given number is a perfect number.
A proper divisor of a number is any divisor except the number itself. For example, the proper divisors of 6 are 1, 2, and 3.
The method should:
- Return
trueif the number is a perfect number - Return
falseif the number is not a perfect number - Return
falsefor numbers less than or equal to 1 - Return
nullfor null input
Examples
Example 1:
Input: 6
Output: true
Explanation: The proper divisors of 6 are 1, 2, and 3. Their sum is 1 + 2 + 3 = 6
Example 2:
Input: 28
Output: true
Explanation: The proper divisors of 28 are 1, 2, 4, 7, and 14. Their sum is 1 + 2 + 4 + 7 + 14 = 28
Example 3:
Input: 12
Output: false
Explanation: The proper divisors of 12 are 1, 2, 3, 4, and 6. Their sum is 1 + 2 + 3 + 4 + 6 = 16, which is not equal to 12
Example 4:
Input: 1
Output: false
Explanation: 1 has no proper divisors, so it is not a perfect number
Example 5:
Input: null
Output: null
Explanation: Null input returns null
Apex Code Editor
Welcome to Lightning Challenge!
How It Works
- • Write your solution in the code editor
- • Connect your Salesforce org to test
- • Submit to check if your solution passes
- • Use hints if you get stuck
Contest Alert
🏆 #CodeEveryDay July 2026
Contest runs July 1 - 31. Complete challenges to climb the leaderboard!
Only the 31 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.