Definition
s(n) > n
Sum of proper divisors strictly exceeds n — smallest is 12.
Abundant numbers are a classic interview warm-up: proper divisors, sum comparisons, and optional O(√n) speedups. This tutorial covers the definition, two JavaScript approaches with Try it Yourself editors, a live preview, algorithm steps, worked examples, edge cases, and complexity.
s(n) > n
Sum of proper divisors strictly exceeds n — smallest is 12.
All vs proper
s(n) = σ(n) − n; abundance is also σ(n) > 2n.
O(√n)
Walk to √n and add divisor pairs — interview-ready fast path.
1 .. n/2
Simple loop matching the definition literally.
Try n
See proper divisors, s(n), and abundant / perfect / deficient.
Editors
Each example opens an interactive editor so you can Run and edit.
An abundant number (also called an excessive number) is a positive integer that is strictly smaller than the sum of its proper divisors — those positive divisors of n that are strictly less than n.
In JavaScript interviews you are usually asked to compute that sum, compare it to n, optionally list abundant values in a range, and discuss an O(√n) optimization.
It trains divisor loops, careful edge cases (n ≤ 1, perfect squares), and the classic deficient / perfect / abundant classification used across number-theory warm-ups.
Only the sum of proper divisors matters.
Proper divisors 1+2+3+4+6 = 16 > 12.
Naive to n/2, or pair divisors up to √n.
Run and edit each sample in the browser.
In short: sum every divisor of n that is less than n; if that sum is greater than n, the number is abundant.
Given a positive integer n, decide whether it is abundant; optionally list every abundant value in a closed interval.
// n = 12
// Proper divisors: 1, 2, 3, 4, 6
// s(12) = 16 > 12 → abundant
//
// Classification:
// abundant if s(n) > n
// perfect if s(n) = n
// deficient if s(n) < n | Item | Type | Description |
|---|---|---|
n / number | number | Positive integer to classify (Example 1). |
| Range bounds | number | Inclusive interval such as [1, 50] (Example 2). |
| Result | boolean / text | Abundant or not; or a printed list of abundant values. |
function properDivisorSum(n):
if n < 1:
return invalid
sum ← 0
for i from 1 to floor(n / 2):
if n mod i = 0:
sum ← sum + i
return sum
function isAbundant(n):
return properDivisorSum(n) > n | Method | Idea | Time (single n) |
|---|---|---|
| Naive scan | Loop i from 1 to n/2, add divisors | O(n) |
| Sqrt pairing | Loop to √n, add i and n/i carefully | O(√n) |
| Goal | Pattern |
|---|---|
| Proper-divisor test | if (n % i === 0) sum += i; for i < n |
| Naive bound | for (let i = 1; i <= Math.floor(n / 2); i++) |
| Sqrt loop | for (let i = 2; i * i <= n; i++) with pair add |
| Abundance check | return sum > n; |
| Equivalent σ form | σ(n) > 2 * n |
All decide abundance — pick based on clarity and scale.
O(n)Matches the definition; great first draft
O(√n)Interview upgrade for larger n
many queriesO(N log N) setup, then O(1) lookups
explain bothStart simple, then mention the √n idea
Reach for abundant-number drills when divisor sums matter.
Quick check of loops, modulo, and edge cases.
Same s(n) helper classifies all three families.
Proper-divisor sums power amicable-number checks next.
List or count abundant values in [L, R].
Abundance is only the precise test s(n) > n.
Key benefit: one small problem that covers divisors, classification, and a clean complexity upgrade path.
Enter a positive integer and see proper divisors, how s(n) is added, and the abundant / perfect / deficient verdict.
Two complete JavaScript programs — fast single check and a range scan. Use Try it Yourself to open an interactive editor, or View Output for the sample console result.
O(√n) divisor-pair check for n = 12.
Returns false for n ≤ 1, then sums proper divisors with divisor pairs up to the square root.
/**
* Returns true if num is abundant (proper divisor sum > num).
* Fast O(√num) scan using divisor pairs.
*/
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;
const pair = Math.floor(num / i);
if (i !== pair) {
sum += pair;
}
}
}
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.");
} Start sum at 1 (every n > 1 is divisible by 1). Walk i only up to √num; when i divides num, add both i and num/i unless they are the same perfect-square root. Then compare sum > num.
List abundant numbers with the simple n/2 scan.
[1, 50]Inner test loops to num/2 (easy to explain). Listing uses process.stdout.write for Node; the Try it editor prints to the page instead.
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;
}
process.stdout.write("Abundant numbers between 1 and 50 are: ");
for (let i = 1; i <= 50; i++) {
if (isAbundant(i)) {
process.stdout.write(i + " ");
}
}
process.stdout.write("\n"); For each i in the range, sum every proper divisor with a loop to i/2, then print i when sum > i. Change the bounds to scan any interval you need.
If n ≤ 1, return not abundant (or reject invalid input).
Naive scan to n/2, or add pairs while i * i ≤ n.
Abundant iff sum > n (perfect if equal, deficient if less).
For n = 12, s(12) = 16 > 12 — abundant.
n = 12Trace the naive proper-divisor sum for the smallest abundant number.
i | 12 % i | Action | Running sum |
|---|---|---|---|
1 | 0 | add 1 | 1 |
2 | 0 | add 2 | 3 |
3 | 0 | add 3 | 6 |
4 | 0 | add 4 | 10 |
5 | 2 | skip | 10 |
6 | 0 | add 6 | 16 |
Compare: 16 > 12 → abundant. (Using σ: divisors sum to 28, and 28 > 24 = 2×12.)
Where abundant-number thinking shows up beyond the interview prompt.
Deficient / perfect / abundant from one s(n) helper.
Example: 7 deficient, 6 perfect, 12 abundant.
Proper-divisor sums define amicable pairs.
Example: next page in this interview chain.
Build fluency with modulo loops and pair tricks.
Example: upgrade O(n) to O(√n) mid-interview.
List or count abundant values in an interval.
Example: all abundant in 1–50.
Sieve-style σ tables for many queries up to N.
Example: Project Euler-style batch problems.
Shows why primes and 1 are never abundant.
Example: s(p) = 1 for prime p.
Pro Tip: open Try it Yourself under each example to tweak number or the range bounds and re-run without leaving the site.
Why these two styles earn interview points.
The n/2 loop is literally “add every proper divisor.”
Same answer with far fewer iterations for large n.
One isAbundant powers single checks and range scans.
Try it Yourself pages let you experiment without a local setup.
Pro Tip: lead with the naive loop for clarity, then offer the √n pairing as the production-friendly variant.
Small habits that keep abundant-number code clean in interviews.
Return false before any divisor loop runs.
Proper divisors stop before n — loops to n/2 do this automatically.
When i === num/i, add that divisor only once in the fast loop.
Edit examples in the browser editors to lock in the logic faster.
Abundant, perfect, and deficient cover the three outcomes.
Pro Tip: dry-run n = 12 on paper (table above) before coding — it catches off-by-one divisor bounds fast.
Mistakes that commonly break abundant-number solutions in JavaScript.
That computes σ(n), not s(n) — every n would look “too big.”
→ Stop at n/2, or subtract n if you summed all divisors.
When i * i === num, adding both i and pair doubles one divisor.
→ Only add the pair when i !== pair.
Starting the loop at i = 2 skips divisor 1 unless you seed it.
→ Initialize sum = 1 for n > 1.
Having factors is not the same as s(n) > n.
→ Always compute and compare the proper-divisor sum.
Huge sums can lose precision past Number.MAX_SAFE_INTEGER.
→ Use BigInt for very large n in production.
Check these inputs before calling the solution done.
s(1) = 0 by convention here; return false early.
s(p) = 1Always deficient — never abundant.
n = 6s(6) = 6 — perfect, not abundant.
Add the square-root divisor only once.
n ≤ 0Reject or treat as not abundant — modulo behaves badly.
Watch Number.MAX_SAFE_INTEGER; prefer BigInt if needed.
Known results for the single-number script.
Input n | Typical line printed |
|---|---|
12 | 12 is an abundant number. |
7 | 7 is not an abundant number. |
1 | 1 is not an abundant number. |
18 | 18 is an abundant number. |
Try these variations — use the Try it editors as a starting point.
n ≥ 1[1, 1000]?1+2+3+4+6 = 16.s(n) > n ↔ σ(n) > 2n — both forms are fine on a whiteboard.n ≤ 1; avoid double-counting at perfect squares in the fast loop.Quick Takeaway: sum proper divisors; if the sum exceeds n, it is abundant — know both the n/2 and √n implementations.
| Approach | Time (single n) | Extra space |
|---|---|---|
| Naive: loop 1 .. n/2 | O(n) | O(1) |
| Sqrt pairing | O(√n) | O(1) |
| Print all in [1, U] (naive each i) | O(U²) worst case | O(1) |
| Print all in [1, U] (sqrt each i) | O(U3/2) | O(1) |
Both scripts on this page use only a few locals — auxiliary space is constant aside from the runtime.
Abundant numbers are a small divisor-sum exercise with clear interview payoff: proper divisors, classification, and an optional √n speedup. Master both the naive and pairing methods, and use the Try it Yourself editors to cement the logic.
Practice the two examples above, then continue to amicable numbers for pairs linked by proper-divisor sums.
Sum proper divisors; if s(n) > n, it is abundant — guard n ≤ 1, and prefer √n pairing for large inputs.
s(n) > n (or σ(n) > 2n) before codingn ≤ 1 and avoid double-counting square rootsn in the proper-divisor sumClassify them the interview-friendly way.
s(n) > n
DefinitionFirst abundant is 12
FactPair divisors to √n
CodeScan 1 .. n/2
CodeEditors for each sample
PracticeThe 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.
Learn how proper-divisor sums define amicable pairs in JavaScript.
9 people found this page helpful