C# Abundant Number Program

Beginner
6 min read
Updated: Sep 2026
2 programs
Live preview

What Is an Abundant Number?

A positive integer n is abundant when its aliquot sum (sum of proper divisors) is strictly greater than n. The difference aliquotSum − n is called the abundance.

Remember
aliquotSum = sum of proper divisors of n
aliquotSum > n  →  abundant
abundance = aliquotSum − n

Proper divisors = positive divisors of n, except n itself
Example: 12 → 1+2+3+4+6 = 16 > 12 → abundant (abundance 4)
ClassConditionExample
DeficientdivSum < n7 → 1 < 7
PerfectdivSum == n6 → 1+2+3 = 6
AbundantdivSum > n12 → 1+2+3+4+6 = 16

First abundant numbers (1–50)

Handy checklist for interviews and unit tests — the first value must be 12.

List
12, 18, 20, 24, 30, 36, 40, 42, 48

How to Check an Abundant Number in C#

Four clear steps — then pick a basic or O(√n) loop.

  1. Reject n <= 1.
  2. Sum proper divisors (aliquot sum).
  3. Compare with n using strict >.
  4. Optionally report abundance sum − n or classify deficient / perfect / abundant.
MethodIdeaTimeBest for
Basic loopAdd every divisor from 1 to n / 2O(n)Interviews, small n
Divisor pairsLoop to √n; add i and n / i (skip n)O(√n)Larger n, optimizations

Pseudocode

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

    divSum = 0
    for i from 1 to floor(n / 2):
        if n mod i == 0:
            divSum = divSum + i

    return divSum > n

Live Preview

Enter any positive integer to see proper divisors, sum, and classification.

Whole numbers n ≥ 1 (capped at 999999). Tap a chip or type a value.

Result
n = 12
Proper divisors (aliquot parts): 1, 2, 3, 4, 6
Aliquot sum = 16
Abundance = 16 − 12 = 4
Compare: 16 > 12
Verdict: ABUNDANT

Worked Walkthrough — n = 12

Check values from 1 through 6. Only 5 does not divide 12 evenly.

Calculation
Proper divisors: 1, 2, 3, 4, 6
Sum:             1 + 2 + 3 + 4 + 6 = 16
Compare:         16 > 12
Result:          abundant (abundance = 4)

C# Programs

Start with the readable O(n) solution. Then use divisor pairs for an O(√n) interview optimization.

Example 1 — Check One Number

Sum proper divisors with a loop to n / 2, then return divSum > n.

C#
using System;

class Program
{
    static 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;
    }

    static void Main()
    {
        int number = 12;

        if (IsAbundant(number))
        {
            Console.WriteLine(number + " is an abundant number.");
        }
        else
        {
            Console.WriteLine(number + " is not an abundant number.");
        }
    }
}

How it works: no proper divisor exceeds num / 2. Add each value that divides evenly, then return whether the sum is greater than num.

Example 2 — O(√n) with Divisor Pairs

For each factor i, also consider n / i — never add n, and do not double-count squares.

C#
using System;

class Program
{
    static 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 <= num / i; i++)
        {
            if (num % i == 0)
            {
                divSum += i;
                int partner = num / i;
                if (partner != i && partner != num)
                {
                    divSum += partner;
                }
            }
        }

        return divSum > num;
    }

    static void Main()
    {
        Console.WriteLine(IsAbundantFast(12)); // True  (abundant)
        Console.WriteLine(IsAbundantFast(28)); // False (perfect)
    }
}

How it works: each divisor i has a partner num / i. Add both once, stopping at √n. The condition i <= num / i also avoids integer overflow.

Edge Cases & Pitfalls

Check these before calling the solution done.

n <= 1

Not abundant

Return false before any loop.

Include n?

Never add n

Including n wrongly makes almost every number look abundant.

>= vs >

Use strict >

>= wrongly labels perfect numbers (6, 28) as abundant.

Squares

No double-count

In pair mode, add the partner only when partner != i.

Time and Space Complexity

ProgramTimeExtra space
Basic loop to n/2O(n)O(1)
Divisor pairs up to √nO(√n)O(1)

Key Takeaways

  • Definition: aliquot sum > n; abundance = sum − n.
  • Exclude n: proper divisors never include the number itself.
  • Two loops: basic 1 … n/2, or pairs up to √n.
  • Test set: 12 true; 6 and 28 false; any prime false.

One line: compute the aliquot sum; if it exceeds n, the number is abundant (abundance = sum − n).

Frequently Asked Questions

A positive integer is abundant when the sum of its proper divisors is greater than the number. For 12, the proper divisors total 16, so 12 is abundant.
Sum every proper divisor of n, then test whether the sum is greater than n. A simple loop checks 1 through n/2; an optimized loop checks divisor pairs through √n.
Compare the proper-divisor sum with n. A smaller sum is deficient, an equal sum is perfect, and a larger sum is abundant.
No. The number 1 has no positive proper divisors, and a prime has only 1 as a proper divisor. Their sums cannot exceed the original number.
The basic loop is O(n). The divisor-pair method is O(√n). Both use O(1) extra space.

Next: Amicable Number

Two numbers that each equal 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.

12 people found this page helpful