Check Abundant Number in C

Beginner
⏱️ 12 min read
📚 Updated: Aug 2026
🎯 3 Code Examples
🚀 Live Preview
Number theory

What You’ll Learn

An abundant number has proper divisors that add up to more than the number itself. This tutorial covers the definition, a live preview, algorithm steps, worked C examples, edge cases, and complexity.

Definition

Sum > n

n is abundant when the sum of its proper divisors is strictly greater than n.

Proper Divisors

Exclude n

Positive divisors smaller than n — for 12 that is 1, 2, 3, 4, and 6.

Basic Loop

1 … n/2

Scan candidates up to n/2, add each divisor, then compare the sum to n.

Sqrt Pairs

Faster path

Walk i up to √n and add both i and n/i (skipping n itself) for O(√n) time.

Live Preview

Try any n

Type a number and see divisors, sum, and abundant / perfect / deficient verdict.

O(n) / O(√n)

Complexity

Both approaches use O(1) extra space; pick the method that matches the interview ask.

Introduction

An abundant number is a positive integer whose proper divisors add up to more than the number itself. The classic first example is 12: proper divisors 1 + 2 + 3 + 4 + 6 = 16, and 16 > 12.

In interviews you usually write a helper that sums proper divisors, then compare that sum with n. The same helper also classifies perfect numbers (sum equals n) and deficient numbers (sum is less than n).

Why it matters?

It trains divisor loops, careful edge handling for 1 and primes, and a natural path to the O(√n) optimization interviewers love to hear.

Key Highlights

Strict Inequality

Abundant needs sum > n — equality is perfect, not abundant.

Smallest Is 12

No abundant number exists below 12 — a great sanity check.

Two Patterns

Simple n/2 loop, or divisor-pair sum up to √n.

Never Primes

Primes only have proper divisor 1, so they are always deficient.

In short: sum the proper divisors of n; if that sum is greater than n, the number is abundant.

📝 Problem & Approach

Given a positive integer n, decide whether it is abundant: whether the sum of its proper divisors is greater than n.

c
/* Example: n = 12
   Proper divisors: 1, 2, 3, 4, 6
   Sum = 16  >  12  → abundant */

Inputs & Outputs

ItemTypeDescription
nintPositive integer to classify (treat n ≤ 1 as not abundant).
Return / printint (0/1) / text1 / message when sum of proper divisors > n.

Minimal workflow

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

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

    return sum > n

Method comparison

MethodIdeaTime
Basic loopAdd every divisor from 1 to n / 2O(n)
Divisor pairsLoop to √n; add both factors (skip n)O(√n)

⚡ Quick Reference

GoalPattern
Is divisor?n % i == 0
Basic upper boundfor (i = 1; i <= num / 2; ++i)
Abundant testsum > n
Perfect testsum == n
Deficient testsum < n
Pair partnern / i (add if i != n / i and partner ≠ n)

📋 Basic vs Sqrt vs Full Sigma

All can decide abundance — clarity and speed differ.

Basic loop
1 .. n/2

Easiest to explain; fine for small n and whiteboard demos

Sqrt pairs
i & n/i

Same answer in O(√n); mention this as the optimization

Sigma form
σ(n) > 2n

Equivalent math: sum of all divisors exceeds 2n

Interview tip
explain both

Lead with basic, then show the pair optimization

Context

When This Problem Shows Up

Reach for abundant-number drills when divisor sums and number classification matter.

  1. Interview warm-ups

    Quick check of loops, modulo tests, and clear boolean returns.

  2. Number-theory intros

    Pairs naturally with perfect and deficient number questions.

  3. Amicable follow-ups

    Abundant checks share the same divisor-sum building block as amicable pairs.

  4. Teaching divisor loops

    Visible example (12) makes the “sum then compare” pattern stick.

  5. Not for huge ranges alone

    Printing every abundant number to a huge limit needs smarter sieves — discuss that separately.

Key benefit: one small problem that covers divisors, classification, edge cases, and a clean O(√n) upgrade.

🔮 Live Preview

Type a positive integer to see its proper divisors, sum, and classification.

Use whole numbers n ≥ 1 (preview capped at 999999).

Live result
Press "Run check" to see details.

Examples Gallery

Three complete C programs — check one number, list a range, and an O(√n) divisor-pair variant. Click View Output to reveal sample console results.

📚 Getting Started

Classify a single integer with the basic loop.

Example 1 — Check One Number

Sum proper divisors with a loop to num / 2, then compare with num.

c
#include <stdio.h>

int isAbundant(int num) {
    if (num <= 1) {
        return 0;
    }
    int sum = 0;

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

    return sum > num;
}

int main(void) {
    int number = 12;

    if (isAbundant(number)) {
        printf("%d is an abundant number.\n", number);
    } else {
        printf("%d is not an abundant number.\n", number);
    }

    return 0;
}

How It Works

Guard num <= 1, then accumulate every i that divides num. Returning sum > num (as 1/0) is the entire definition of abundance.

📈 Practical Patterns

Reuse the helper across a range.

Example 2 — Print Abundant Numbers from 1 to 50

Call the same check in a loop and print matches on one line.

c
#include <stdio.h>

int isAbundant(int num) {
    if (num <= 1) {
        return 0;
    }
    int sum = 0;

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

    return sum > num;
}

int main(void) {
    printf("Abundant numbers between 1 and 50 are: ");

    for (int i = 1; i <= 50; ++i) {
        if (isAbundant(i)) {
            printf("%d ", i);
        }
    }

    printf("\n");
    return 0;
}

How It Works

The helper stays pure; the outer loop only decides what to print. Notice the first hit is 12 — a useful self-check when you rewrite the function.

⚡ Interview Optimization

Same verdict in O(√n) using divisor pairs.

Example 3 — Sum Divisor Pairs up to √n

For each factor i, also consider n / i, but never add n itself.

c
#include <stdio.h>

/* Returns 1 if num is abundant, 0 otherwise */
int isAbundant(int num) {
    if (num <= 1) {
        return 0;
    }
    int sum = 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;
}

int main(void) {
    printf("%d\n", isAbundant(12));
    printf("%d\n", isAbundant(28));
    return 0;
}

How It Works

Start sum at 1, then for each i from 2 while i * i <= num add both sides of the pair when they differ. Because the loop starts at 2, partner num / i is never num itself. 12 is abundant (1); 28 is perfect, so the second call prints 0.

🧠 How the Algorithm Decides

1

Validate n

If n <= 1, return 0 immediately — not abundant under this definition.

Guard
2

Sum divisors

Add every proper divisor found by the basic loop or the pair method.

Accumulate
3

Compare

Test sum > n. Equality means perfect; less means deficient.

Verdict
=

Classification done

Return or print whether n is abundant based on that strict inequality.

🔎 Worked Walkthrough — n = 12

Trace the basic method for 12. Loop i from 1 to 12 / 2 = 6 and add every divisor.

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

Final check: 16 > 12abundant.

Use Cases

Where abundant-number checks (and their divisor sums) show up beyond the prompt.

1. Number Classification

Split integers into deficient, perfect, and abundant buckets.

Example: 7 / 6 / 12 in one helper.

2. Amicable Pairs

Proper-divisor sums are the core of amicable-number checks.

Example: 220 and 284 share the same sum helper.

3. Interview Drills

Shows loops, modulo, and optional sqrt optimization cleanly.

Example: “write isAbundant(n)” prompts.

4. Teaching Divisors

Concrete numbers make “exclude n itself” easy to remember.

Example: chalkboard walkthrough of 12.

5. Project Euler Warm-Ups

Several classic problems ask for sums over abundant numbers.

Example: non-abundant sums style tasks.

6. Complexity Practice

Compare O(n) vs O(√n) on the same boolean question.

Example: time both helpers on large n.

Pro Tip: keep one proper_divisor_sum(n) helper and derive abundant / perfect / deficient from it — less duplicated logic.

Advantages

Why these approaches work well in interviews and classwork.

  1. 1. Definition Maps to Code

    Sum proper divisors, compare with n — almost no translation gap.

  2. 2. Easy Optimization Story

    You can start O(n) and upgrade to O(√n) without changing the problem statement.

  3. 3. Reusable Sum Helper

    The same function powers perfect, deficient, and amicable problems.

  4. 4. Tiny Extra Memory

    Both methods need only a few integers — O(1) extra space.

Pro Tip: say the definition out loud first, then code the sum — interviewers score clarity as much as the loop.

Usage Tips

Small habits that keep abundant-number code interview-ready.

  1. 1. Exclude n Explicitly

    Proper divisors never include the number; looping only to n / 2 makes that automatic.

  2. 2. Use Strict >

    Perfect numbers satisfy equality — do not treat them as abundant.

  3. 3. Guard Tiny Inputs

    Return false for n <= 1 before any loop.

  4. 4. Name the Helper Clearly

    isAbundant vs properDivisorSum — pick names that match what the function returns.

  5. 5. Spot-Check Known Values

    Assert 12 returns 1, while 6, 28, and 7 return 0 before moving on.

Pro Tip: dry-run 12 on paper once — it catches off-by-one upper bounds faster than guessing.

Common Pitfalls

Mistakes that commonly break abundant-number solutions.

  1. 1. Including n in the Sum

    Adding the number itself turns every n into “abundant” via sum ≥ n + 1.

    → Loop only to n / 2, or skip the partner when it equals n.

  2. 2. Using >= Instead of >

    That wrongly labels perfect numbers as abundant.

    → Abundance requires a strict greater-than comparison.

  3. 3. Double-Counting Square Roots

    When i * i == n, adding both i and n / i counts the root twice.

    → Only add the partner when partner != i.

  4. 4. Skipping the n <= 1 Guard

    Empty ranges or awkward special cases can confuse beginners.

    → Return false early for tiny inputs.

  5. 5. Forgetting Primes Are Never Abundant

    A wrong sum that exceeds 1 for a prime is a bug, not a discovery.

    → Spot-check a few primes after coding.

Edge Cases

Check these inputs before calling the solution done.

n <= 1

Not abundant

Return 0 — no positive proper-divisor sum beats n.

Prime n

Always deficient

Only proper divisor is 1, so the sum cannot exceed n.

Perfect

6, 28, …

Sum equals n — return 0 for the abundant check.

n = 12

Smallest abundant

Great golden test: must return true.

Squares

Pair edge

When using sqrt pairs, do not double-count the square root.

Large n

Prefer O(√n)

The basic loop to n/2 gets slow; switch to divisor pairs.

⚖️ Classification Worth Knowing

Handy facts interviewers sometimes ask as follow-ups.

  • Three-way split. Every positive integer is deficient, perfect, or abundant based on its proper-divisor sum.
  • Abundance. The abundance of n is sum - n; abundant numbers have positive abundance.
  • Sigma form. Equivalently, n is abundant when σ(n) > 2n, where σ sums all positive divisors.
  • Even vs odd. Most small abundant numbers are even; odd abundant numbers exist but are much larger.

🎯 Practice Problems

Try these variations to lock in the pattern.

1. Classify any n

  • Return "deficient", "perfect", or "abundant"
  • Reuse one divisor-sum helper

2. Count abundants in a range

  • How many abundant numbers are in 1…100?
  • Compare basic vs sqrt helpers for speed

3. List with abundance

  • Print n and sum - n for each hit
  • Confirms you understand the surplus

4. Implement σ(n) > 2n

  • Sum all divisors including n
  • Show it matches the proper-divisor definition

Notes

  • Proper vs all. Proper divisors exclude n; σ(n) includes n — keep the definitions straight when comparing formulas.
  • 12 is the smallest abundant number — if your range printer starts later, something is wrong.
  • Perfect numbers are not abundant. Test 6 and 28 as negative cases.
  • Mention both O(n) and O(√n) when asked about complexity — that shows depth.

Quick Takeaway: sum proper divisors; if the sum is greater than n, the number is abundant.

⏱️ Time and Space Complexity

ProgramTimeExtra space
Basic loop to n/2O(n)O(1)
Divisor pairs up to √nO(√n)O(1)
Range scan 1…m (basic)O(m²) worst caseO(1)
Wrap Up

🎉 Conclusion

Abundant numbers are a clean divisor-sum exercise: exclude n, add what remains, and test a strict greater-than comparison. Master the basic loop first, then explain the O(√n) pair method when interviewers ask about performance.

Practice the three examples above, then continue to amicable numbers — they reuse the same proper-divisor sum idea.

Never include n in the sum, never treat perfect numbers as abundant, and validate tiny inputs early.

💡 Best Practices

✅ Do

  • State the definition before coding
  • Use sum > n (strict)
  • Guard n <= 1
  • Mention the O(√n) pair optimization
  • Test 12, 6, 28, and a prime

❌ Don’t

  • Add n into the divisor sum
  • Confuse perfect with abundant
  • Double-count square roots in pair mode
  • Skip complexity discussion for large n
  • Forget that primes are never abundant

Key Takeaways

Knowledge Unlocked

Five things to remember about abundant numbers

Classify integers the interview-friendly way.

5
Core concepts
/ 02

Proper

Divisors exclude n

Math
n 03

Basic

Loop 1 … n/2

Code
04

Fast

Divisor pairs to √n

Code
O 05

Complexity

O(n) or O(√n)

Analysis

❓ 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 18, proper divisors 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 only has proper divisor 1, so the sum is 1 and cannot be greater than p.
No proper divisor of n can be larger than n/2. So checking beyond n/2 is unnecessary in the simple approach.
Perfect: sum equals n. Deficient: sum is less than n. Abundant: sum is greater than n. Together they classify every positive integer.
Start with the simple method (easy to understand), then mention the sqrt optimization using divisor pairs for better performance.
The basic loop to n/2 is O(n). Summing divisor pairs up to sqrt(n) is O(√n). Both use O(1) extra space.
Every integer n > 1 has 1 as a divisor. The loop starts at i = 2, so sum begins at 1 to include that divisor without a separate iteration.

Did you Know? 🔊

The ancient Greeks classified numbers as deficient, perfect, or abundant based on whether the sum of proper divisors was less than, equal to, or greater than the number. 6 is perfect (1+2+3 = 6); 12 is the smallest abundant number.

Continue to Amicable Number

Learn how two numbers can 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.

9 people found this page helpful