C# Abundant Number Program

Beginner
6 min read
Updated: Sep 2026
3 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

Equivalent form: σ(n) > 2n, where σ(n) sums all positive divisors (including n).

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

Cheat sheet

GoalPattern
Is divisor?n % i == 0
Basic boundfor (i = 1; i <= n / 2; i++)
Abundant testdivSum > n (strict)
Pair partnern / i — add if i != n / i and partner ≠ 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

Basic method: loop i from 1 to 12 / 2 = 6. Add every i that divides 12.

i12 % iActiondivSum
10Add 11
20Add 23
30Add 36
40Add 410
52Skip10
60Add 616

Final check: 16 > 12 → abundant with abundance 16 − 12 = 4. (12 is the smallest abundant number.)

C# Programs

Three programs: check one number, classify with abundance + user input, and an O(√n) interview variant. Use View Output for sample results.

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

1. Guard tiny inputs. Return false when num <= 1 — nothing below 2 is abundant.

2. Scan to half. Loop i from 1 to num / 2. No proper divisor can be larger than half of num.

3. Accumulate and compare. Add every divisor to divSum, then return divSum > num. For 12: 1+2+3+4+6 = 16, and 16 > 12.

Example 2 — Classify + Abundance (User Input)

Interview follow-up: print deficient, perfect, or abundant, plus abundance. Uses int.TryParse for safe input.

C#
using System;

class Program
{
    static int AliquotSum(int num)
    {
        if (num <= 1)
        {
            return 0;
        }

        int divSum = 0;
        for (int i = 1; i <= num / 2; i++)
        {
            if (num % i == 0)
            {
                divSum += i;
            }
        }
        return divSum;
    }

    static void Main()
    {
        Console.Write("Enter a positive integer: ");
        if (!int.TryParse(Console.ReadLine(), out int n) || n < 1)
        {
            Console.WriteLine("Please enter a positive integer.");
            return;
        }

        int sum = AliquotSum(n);
        int abundance = sum - n;

        if (sum > n)
        {
            Console.WriteLine(n + " is abundant (abundance = " + abundance + ").");
        }
        else if (sum == n)
        {
            Console.WriteLine(n + " is perfect (abundance = 0).");
        }
        else
        {
            Console.WriteLine(n + " is deficient (abundance = " + abundance + ").");
        }
    }
}

How It Works

1. Safe input. int.TryParse avoids FormatException on bad text.

2. One sum, three labels. Compare sum to n: greater → abundant, equal → perfect, less → deficient.

3. Abundance. sum - n is positive for abundant, 0 for perfect, and negative for deficient. For 12: abundance 4. Expected abundant values up to 50: 12 18 20 24 30 36 40 42 48.

Example 3 — 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 * i <= num; 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

1. Seed with 1. Start divSum at 1 and begin the loop at 2.

2. Walk to √n. While i * i <= num, each factor i has a partner num / i.

3. Add carefully. Always add i. Add partner only when it differs from i and is not num. Same verdict as Example 1 — faster loop. Explain the basic method first in interviews.

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.

Prime

Always deficient

Only proper divisor is 1 — sum cannot exceed n.

Perfect

6, 28, …

Sum equals n — IsAbundant must return false.

Squares

No double-count

In pair mode, add the root only once when i * i == n.

Time and Space Complexity

ProgramTimeExtra space
Basic loop to n/2O(n)O(1)
Divisor pairs up to √nO(√n)O(1)
Classify 1…m (basic)O(m²) worst caseO(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 n is abundant when the sum of its proper divisors (aliquot sum) is greater than n. Example: 12 → 1+2+3+4+6 = 16, and 16 > 12.
Abundance is aliquotSum − n. For 12 it is 16 − 12 = 4. For a perfect number abundance is 0; for a deficient number it is negative.
The aliquot sum is another name for the sum of proper divisors — all positive divisors of n except n itself.
Proper divisors are positive divisors of n excluding n itself. For 18 they are 1, 2, 3, 6, and 9.
No. 1 has no positive proper divisors, so the sum is 0, which is not greater than 1.
No. A prime p has only proper divisor 1, so the sum is 1 and cannot exceed p.
Yes, but they are rare among small values. The smallest odd abundant number is 945. Every abundant number below that is even.
Perfect: sum equals n. Deficient: sum is less than n. Abundant: sum is greater than n. Every positive integer is exactly one of these three.
Start with the simple 1..n/2 loop, then show the O(√n) divisor-pair upgrade when asked to optimize.
Basic loop to n/2 is O(n). Divisor pairs up to √n is O(√n). Both use O(1) extra space.

Did you know?

The smallest abundant number is 12 (abundance 4). The smallest odd abundant number is 945 — almost all small abundants are even.

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