C++ Abundant Number Program

Beginner
5 min read
Updated: Oct 2026
3 programs
Live preview

What Is an Abundant Number?

An abundant number is a positive integer whose proper divisors sum to more than the number itself.

Remember
n is abundant  ↔  sum(proper divisors of n) > n

Proper divisors = positive divisors of n except n itself

Example: 12
  1 + 2 + 3 + 4 + 6 = 16
  16 > 12  → abundant
nProper divisorsSumClass
121, 2, 3, 4, 616Abundant
181, 2, 3, 6, 921Abundant
281, 2, 4, 7, 1428Perfect
101, 2, 58Deficient

How to Check an Abundant Number in C++

Sum the proper divisors, then compare with n.

  1. Reject n <= 1 (not abundant).
  2. Sum every divisor in 1 .. n/2 (or use √n pairs).
  3. Return true when that sum is greater than n.
MethodIdeaTimeBest for
Loop to n/2Add every divisor < nO(n)Interviews, clarity
√n pairsAdd i and n/i, skip nO(√n)Faster checks
Range scanReuse the helperO(N·cost)Listing matches

Pseudocode

Pseudocode
function IsAbundant(n):
    if n <= 1:
        return false

    sum = 0
    for i from 1 to n / 2:
        if n mod i == 0:
            sum = sum + i

    return sum > n

Cheat Sheet

Keep these facts handy while writing the program.

TopicDetail
Testsum(proper divisors) > n
Proper divisorsPositive divisors of n except n
Basic loopi = 1 .. n/2
Smallest12
Perfectsum equals n (e.g. 28)
Deficientsum less than n (e.g. 10)
1..5012 18 20 24 30 36 40 42 48

Live Preview

Enter a positive integer to see its proper divisors, their sum, and the verdict.

Positive whole numbers. Tap a chip or type a value.

Result
n = 12
Proper divisors: 1, 2, 3, 4, 6
Sum = 16
Verdict: ABUNDANT (16 > 12)

Worked Walkthrough — n = 12

List proper divisors, add them, then compare with 12.

Calculation
Candidates i = 1 .. 12/2 = 6

1 | 12  → add 1
2 | 12  → add 2
3 | 12  → add 3
4 | 12  → add 4
5 ✗
6 | 12  → add 6

Sum = 1+2+3+4+6 = 16
16 > 12  → abundant

C++ Programs

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;
}

How It Works

  1. Return false immediately when num <= 1.
  2. Loop i from 1 to num / 2 — no proper divisor is larger.
  3. Add every i that divides num.
  4. For 12 the sum is 16, so divSum > num is true.
  5. 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;
}

How It Works

  1. Outer loop visits every integer from 1 to 50.
  2. Each value is tested with the same isAbundant helper.
  3. Matches are printed with a trailing space.
  4. The first hit is 12 — a useful self-check.
  5. 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;
}

How It Works

  1. Start with 1 (always a proper divisor when num > 1).
  2. Loop i from 2 while i * i <= num.
  3. When i divides num, add i and its partner num / i if different.
  4. Skip the partner when it equals num so you never include the number itself.
  5. 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.

Time and Space Complexity

ProgramTimeExtra space
Loop to n/2O(n)O(1)
√n pairsO(√n)O(1)
Range 1..N (basic)O(N²)O(1)

Explain the simple method first in interviews, then mention the √n optimization.

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.

Next: Amicable Number

Find pairs where each number is the proper-divisor sum of the other.

Amicable number tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

18 people found this page helpful