JavaScript Abundant Number Program

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

What Is an Abundant Number?

A positive integer n is abundant when the sum of its proper divisors is strictly greater than n. Proper divisors are positive divisors of n except n itself.

Remember
sum(proper divisors of n) > n  →  abundant

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

Compare:
  deficient  → sum < n
  perfect    → sum == n
  abundant   → sum > n
nProper divisorsSumResult
121+2+3+4+616Abundant
281+2+4+7+1428Perfect
101+2+58Deficient
1none0Not abundant

How to Check an Abundant Number in JavaScript

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

  1. Reject n <= 1.
  2. Sum every proper divisor of n.
  3. Return whether that sum is strictly greater than n.
  4. Use a loop to n / 2 for clarity, or divisor pairs to √n for speed.
MethodIdeaTimeBest for
Basic loopAdd every divisor from 1 to n / 2O(n)Interviews, small n
Divisor pairsLoop to √n; add i and n / iO(√n)Larger n, optimizations

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)

JavaScript Programs

Start with the clear loop to n/2. Then list a range, and finish with the faster √n pair method. Each example has a Try it Yourself editor.

Example 1 — Check One Number

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

JavaScript
function isAbundant(num) {
  if (num <= 1) {
    return false;
  }

  let sum = 0;
  for (let i = 1; i <= Math.floor(num / 2); i++) {
    if (num % i === 0) {
      sum += i;
    }
  }

  return sum > num;
}

const number = 12;
if (isAbundant(number)) {
  console.log(number + " is an abundant number.");
} else {
  console.log(number + " is not an abundant number.");
}
Try It Yourself

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 sum > num is true.
  5. Return that comparison as a boolean.

Example 2 — Abundant Numbers from 1 to 50

Reuse the helper and print every match on one line.

JavaScript
function isAbundant(num) {
  if (num <= 1) {
    return false;
  }

  let sum = 0;
  for (let i = 1; i <= Math.floor(num / 2); i++) {
    if (num % i === 0) {
      sum += i;
    }
  }

  return sum > num;
}

console.log("Abundant numbers between 1 and 50 are:");
let line = "";
for (let i = 1; i <= 50; i++) {
  if (isAbundant(i)) {
    line += i + " ";
  }
}
console.log(line.trim());
Try It Yourself

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 collected into one space-separated line.
  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.

JavaScript
function isAbundant(num) {
  if (num <= 1) {
    return false;
  }

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

  return sum > num;
}

console.log(isAbundant(12)); // true  (abundant)
console.log(isAbundant(28)); // false (perfect)
Try It Yourself

How It Works

  1. Start sum at 1 because every n > 1 has divisor 1.
  2. Loop while i * i <= num so you only walk up to √n.
  3. When i divides num, add i and also num / i if they differ.
  4. Because the loop starts at 2, partner num / i is never num itself.
  5. 12 prints true (abundant); 28 prints false (perfect, not abundant).

Edge Cases & Pitfalls

Check these before calling the solution done.

1

Not abundant

No proper divisors; sum is 0. Guard with n <= 1.

Primes

Always deficient

A prime has only proper divisor 1, so it cannot be abundant.

Perfect

Sum equals n

28 is perfect, not abundant. Use strict >, not >=.

Sqrt method

Do not add n

When adding pairs, skip the number itself — proper divisors exclude n.

Time and Space Complexity

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

In interviews, explain the simple loop first, then mention the √n optimization.

Key Takeaways

  • Definition: proper-divisor sum is strictly greater than n.
  • Classic: 12 → 1+2+3+4+6 = 16 > 12.
  • Two loops: basic 1..n/2, or optimized pairs to √n.
  • Test set: 12 and 18 abundant; 28 perfect; 10 deficient; 1 no.

One line: if the proper divisors add up to more than the number, 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.
Use the Try it Yourself links under each code sample — they open an in-browser editor with the same logic so you can edit the input and Run.

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