Check Whether a Number Is an Abundant Number
Decide whether a number is abundant by comparing the sum of its proper divisors to itself.
A number is abundant when the sum of its proper divisors (all divisors except the number itself) is greater than the number. Add every i from 1 to n/2 that divides n, then return true when that sum exceeds n. For 12 the proper divisors 1+2+3+4+6 = 16 exceed 12, so 12 is abundant.
Problem Statement
An abundant number is a positive integer for which the sum of its proper
divisors (every divisor except the number itself) is greater than the number.
Given n, decide whether it is abundant and return true or false.
For example, the proper divisors of 12 are 1, 2, 3, 4, 6, which sum to
16. Since 16 > 12, the number 12 is abundant.
Input: A single positive integer n.
Output: A boolean: true if n is abundant, otherwise false.
Examples
Input: 12
Output: trueProper divisors 1+2+3+4+6 = 16, which is greater than 12.
Input: 15
Output: falseProper divisors 1+3+5 = 9, which is less than 15.
Constraints
n >= 1 and fits in a 32-bit intProper divisors exclude n itself
Think Before You Code
Reveal the questions to ask yourself first
- Which divisors count — should the number itself be included?
- How far do you need to loop to find every proper divisor?
- Is the answer "greater than", not "greater than or equal to"?
Hints
Open them one at a time — try after each before revealing the next.
Hint 1
Hint 2
Hint 3
Approach
Reveal the step-by-step approach
Add up the proper divisors and compare.
- Set
sum = 0. - For
ifrom1ton / 2:- if
n % i == 0, additosum.
- if
- Return
sum > n.
Stopping at n / 2 is safe because no divisor other than n itself can be
larger than half of n.
Dry Run
Walk through the example step by step
Checking n = 12 (loop i from 1 to 6):
i | 12 % i | divisor? | sum
--+--------+----------+-----
1 | 0 | yes | 1
2 | 0 | yes | 3
3 | 0 | yes | 6
4 | 0 | yes | 10
5 | 2 | no | 10
6 | 0 | yes | 16
sum (16) > 12 -> true
Solution
Reveal the full Java solution
public class AbundantNumber {
public static boolean isAbundant(int n) {
if (n <= 0) return false;
int sum = 0;
for (int i = 1; i <= n / 2; i++) {
if (n % i == 0) {
sum += i;
}
}
return sum > n;
}
public static void main(String[] args) {
System.out.println(isAbundant(12)); // true
System.out.println(isAbundant(15)); // false
}
}
The definition hinges on "proper" divisors, so the number itself is deliberately
excluded — that is exactly why the loop runs only up to n / 2. Once the sum of
those divisors is known, a single strict comparison sum > n gives the answer.
Using >= instead would incorrectly classify perfect numbers as abundant.
O(n) — the loop runs about n/2 timesSpace: O(1)Common Mistakes
- Including n itself in the divisor sum, which changes the classification.
- Using `>=` and mislabelling perfect numbers as abundant.
Edge Cases to Test
- Small numbers like 1 and 15 are not abundant (their divisor sums are small).
- 12 is the smallest abundant number, a good sanity check.
Interview Follow-Ups
- How would you speed the loop up to O(sqrt n) by pairing divisors?
- How would you also classify the number as deficient or perfect?
Practising for Java interviews?
CodeBegun's Java Full Stack with AI program builds this problem-solving muscle with mentor review and mock interviews.
Explore the Java Full Stack program →