Start with the clear loop to n/2. Then list a range, and finish with the faster √n pair method.
Example 1 — Check One Number
Sum proper divisors with a loop to num / 2, then compare with num.
Java
class AbundantCheck {
static boolean isAbundant(int num) {
if (num <= 1) {
return false;
}
int sum = 0;
for (int i = 1; i <= num / 2; i++) {
if (num % i == 0) {
sum += i;
}
}
return sum > num;
}
public static void main(String[] args) {
int number = 12;
if (isAbundant(number)) {
System.out.println(number + " is an abundant number.");
} else {
System.out.println(number + " is not an abundant number.");
}
}
}
Output
12 is an abundant number.
How It Works
Return false immediately when num <= 1.
Loop i from 1 to num / 2 — no proper divisor is larger.
Add every i that divides num.
For 12 the sum is 16, so sum > num is true.
Return that comparison as a boolean.
Example 2 — Abundant Numbers from 1 to 50
Reuse the helper and print every match on one line.
Java
class AbundantRange {
static boolean isAbundant(int num) {
if (num <= 1) {
return false;
}
int sum = 0;
for (int i = 1; i <= num / 2; i++) {
if (num % i == 0) {
sum += i;
}
}
return sum > num;
}
public static void main(String[] args) {
System.out.print("Abundant numbers between 1 and 50 are: ");
for (int i = 1; i <= 50; i++) {
if (isAbundant(i)) {
System.out.print(i + " ");
}
}
System.out.println();
}
}
Output
Abundant numbers between 1 and 50 are: 12 18 20 24 30 36 40 42 48
How It Works
Outer loop visits every integer from 1 to 50.
Each value is tested with the same isAbundant helper.
Matches are printed with a trailing space.
The first hit is 12 — a useful self-check.
Keeping the helper pure makes range listing easy.
Example 3 — Sum Divisor Pairs up to √n
For each factor i, also add n / i, but never add n itself.
Java
class AbundantSqrt {
static boolean isAbundant(int num) {
if (num <= 1) {
return false;
}
int sum = 1; // 1 is always a proper divisor for num > 1
for (int i = 2; i * i <= num; i++) {
if (num % i == 0) {
sum += i;
if (i != num / i) {
sum += num / i;
}
}
}
return sum > num;
}
public static void main(String[] args) {
System.out.println(isAbundant(12)); // true (abundant)
System.out.println(isAbundant(28)); // false (perfect)
}
}
Output
true
false
How It Works
Start sum at 1 because every n > 1 has divisor 1.
Loop while i * i <= num so you only walk up to √n.
When i divides num, add i and also num / i if they differ.
Because the loop starts at 2, partner num / i is never num itself.
12 prints true (abundant); 28 prints false (perfect, not abundant).
Edge Cases & Pitfalls
Check these before calling the solution done.
1
Not abundant
No proper divisors; sum is 0. Guard with n <= 1.
Primes
Always deficient
A prime has only proper divisor 1, so it cannot be abundant.
Perfect
Sum equals n
28 is perfect, not abundant. Use strict >, not >=.
Sqrt method
Do not add n
When adding pairs, skip the number itself — proper divisors exclude n.
Analysis
Time and Space Complexity
Program
Time
Extra space
Loop to n/2
O(n)
O(1)
Divisor pairs to √n
O(√n)
O(1)
Range 1..N (basic)
O(N²)
O(1)
In interviews, explain the simple loop first, then mention the √n optimization.
Remember
Key Takeaways
Definition: proper-divisor sum is strictly greater than n.
Classic: 12 → 1+2+3+4+6 = 16 > 12.
Two loops: basic 1..n/2, or optimized pairs to √n.
Test set: 12 and 18 abundant; 28 perfect; 10 deficient; 1 no.
One line: if the proper divisors add up to more than the number, it is abundant.
Frequently Asked Questions
A positive integer n is abundant when the sum of its proper divisors is greater than n. Example: 12 is abundant because 1+2+3+4+6 = 16, and 16 > 12.
Proper divisors are positive divisors smaller than the number itself. For 12 they are 1, 2, 3, 4, and 6.
Perfect: divisor sum equals n. Deficient: sum is less than n. Abundant: sum is greater than n.
No. 1 has no positive proper divisors, so the sum is 0, which is not greater than 1.
The basic loop to n/2 is O(n). Summing divisor pairs up to √n is O(√n). Both use O(1) extra space.