A number is abundant if the sum of its proper divisors (all positive divisors excluding the number itself) is greater than the number. For example, 12 is abundant because its proper divisors are 1, 2, 3, 4, and 6, which sum to 16, and 16 is greater than 12. Write a method that returns true if the given number is abundant, and false otherwise. Return false for numbers less than or equal to 0, and false for null input.
Examples:
Input: n = 12
Output: true
Explanation: Proper divisors are 1, 2, 3, 4, 6 which sum to 16, and 16 > 12
Input: n = 18
Output: true
Explanation: Proper divisors are 1, 2, 3, 6, 9 which sum to 21, and 21 > 18
Input: n = 6
Output: false
Explanation: Proper divisors are 1, 2, 3 which sum to 6, and 6 is not greater than 6
Input: n = 7
Output: false
Explanation: Proper divisors are 1 only, which sums to 1, and 1 is not greater than 7
Input: n = null
Output: false
Explanation: Null input returns false
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
Note
You can test your code by connecting to Salesforce, but to save your progress and earn points, you'll need to create an account. Your solutions and achievements will be tracked automatically once you're logged in.