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.
C++
#include <iostream>
bool isAbundant(int num) {
if (num <= 1) {
return false;
}
int divSum = 0;
for (int i = 1; i <= num / 2; i++) {
if (num % i == 0) {
divSum += i;
}
}
return divSum > num;
}
int main() {
int number = 12;
if (isAbundant(number)) {
std::cout << number << " is an abundant number.\n";
} else {
std::cout << number << " is not an abundant number.\n";
}
return 0;
}
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 divSum > num is true.
Return that comparison as the abundance check.
Example 2 — Abundant Numbers from 1 to 50
Reuse the helper and print every match on one line.
C++
#include <iostream>
bool isAbundant(int num) {
if (num <= 1) {
return false;
}
int divSum = 0;
for (int i = 1; i <= num / 2; i++) {
if (num % i == 0) {
divSum += i;
}
}
return divSum > num;
}
int main() {
std::cout << "Abundant numbers between 1 and 50 are:\n";
for (int value = 1; value <= 50; value++) {
if (isAbundant(value)) {
std::cout << value << " ";
}
}
std::cout << "\n";
return 0;
}
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.
C++
#include <iostream>
bool isAbundantFast(int num) {
if (num <= 1) {
return false;
}
int divSum = 1; // 1 is always a proper divisor for num > 1
for (int i = 2; i * i <= num; i++) {
if (num % i == 0) {
divSum += i;
int partner = num / i;
if (partner != i && partner != num) {
divSum += partner;
}
}
}
return divSum > num;
}
int main() {
std::cout << (isAbundantFast(12) ? "true" : "false") << "\n";
std::cout << (isAbundantFast(28) ? "true" : "false") << "\n";
return 0;
}
Output
true
false
How It Works
Start with 1 (always a proper divisor when num > 1).
Loop i from 2 while i * i <= num.
When i divides num, add i and its partner num / i if different.
Skip the partner when it equals num so you never include the number itself.
12 is abundant; 28 is perfect (sum = 28), so the second call is false.
Edge Cases & Pitfalls
Check these before calling the solution done.
n = 1
Not abundant
1 has no positive proper divisors. Guard n <= 1 first.
Include n?
Never add n itself
Proper divisors exclude the number. Including n breaks the definition.
Perfect
Sum == n is not abundant
28 sums to 28 — perfect, not abundant. Need a strict greater-than.
Primes
Always deficient
A prime only has proper divisor 1, so it cannot be abundant.
Analysis
Time and Space Complexity
Program
Time
Extra space
Loop to n/2
O(n)
O(1)
√n pairs
O(√n)
O(1)
Range 1..N (basic)
O(N²)
O(1)
Explain the simple method first in interviews, then mention the √n optimization.
Remember
Key Takeaways
Definition: proper-divisor sum > n.
Smallest: 12 (sum 16).
Methods: loop to n/2 for clarity; √n pairs for speed.
Neighbors: perfect = sum; deficient = sum < n.
One line: if the proper divisors add up to more than n, 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.