Definition
s(n) > n
Proper divisor sum exceeds the number.
An abundant number has a proper-divisor sum greater than itself. For example, 12 is abundant because 1 + 2 + 3 + 4 + 6 = 16 and 16 > 12. This tutorial covers the definition, deficient/perfect neighbors, a live checker, worked PHP examples, edge cases, and complexity.
s(n) > n
Proper divisor sum exceeds the number.
Exclude n
Positive divisors of n except n itself.
Simple loop
No proper divisor exceeds intdiv(n, 2).
s(n) vs n
Deficient, perfect, or abundant.
Try 12 / 18
See divisors, sum, and verdict live.
12 is first
12 is the smallest abundant number.
An abundant number is a positive integer whose proper divisors add up to more than the number itself. Using s(n) for that sum: abundant means s(n) > n, perfect means s(n) = n, and deficient means s(n) < n.
In interviews you usually write a helper that sums proper divisors, then compare with n. One is never abundant: by convention s(1) = 0.
It is a classic divisor-sum interview problem that connects loops, modulo, and number-theory vocabulary — and pairs naturally with perfect and amicable checks.
Proper divisors sum past n.
Do not add the number itself.
s(1) = 0 by convention.
Deficient / perfect too.
In short: sum divisors from 1 to intdiv(n, 2); abundant when that sum is greater than n.
Given a positive integer n, decide whether it is abundant by comparing the sum of its proper divisors with n.
# 12: 1+2+3+4+6 = 16 -> abundant
# 18: 1+2+3+6+9 = 21 -> abundant
# 6: 1 + 2 + 3 = 6 -> perfect
# 7: 1 = 1 -> deficient | Item | Type | Description |
|---|---|---|
$n / $num | int | Positive integer to classify. |
| Return | bool | true when proper divisor sum is greater than n. |
| Classification | text | Deficient, perfect, or abundant. |
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 | Method | Idea | Notes |
|---|---|---|
| Scan to n / 2 | Add every proper divisor | Interview default — clearest |
| Pair to sqrt(n) | Add i and n / i | Faster; careful with squares |
| Classify s(n) vs n | One sum, three labels | Deficient / perfect / abundant |
| Goal | Pattern |
|---|---|
| Loop bound | for ($i = 1; $i <= intdiv($n, 2); $i++) |
| Is divisor? | if ($n % $i === 0) { $divSum += $i; } |
| Abundant? | return $divSum > $n; |
| Perfect | $divSum === $n |
| Deficient | $divSum < $n |
| Guard 1 | if ($n <= 1) return false; |
Same divisor sum — different comparisons to n.
s(n) > nThis page — e.g. 12, 18
s(n) = ne.g. 6, 28 — related topic
s(n) < nMost numbers, including primes
exclude nProper divisors only
Reach for a proper-divisor sum whenever you need to classify abundance.
Divisors, sums, and classification.
Find all divisors with %.
Same sum, different comparison.
List abundant values in a band (e.g. 1..50).
Naive O(n) per check gets costly fast.
Key benefit: one clear loop that teaches proper divisors, classification, and the famous example 12.
Enter a positive integer and inspect proper divisors, sum, and verdict.
Three complete PHP programs — check 12, list abundant numbers from 1 to 50, and classify deficient/perfect/abundant. Click View Output to reveal sample console results.
A reusable helper and the classic example 12.
Test a fixed value (12) with a helper function.
<?php
function isAbundant(int $num): bool
{
if ($num <= 1) {
return false;
}
$divSum = 0;
for ($i = 1; $i <= intdiv($num, 2); $i++) {
if ($num % $i === 0) {
$divSum += $i;
}
}
return $divSum > $num;
}
$number = 12;
if (isAbundant($number)) {
echo $number . " is an abundant number.";
} else {
echo $number . " is not an abundant number.";
}
?> The loop adds every proper divisor of 12: 1, 2, 3, 4, and 6. Their sum is 16, which is greater than 12, so the helper returns true.
Reuse the helper to find abundant values nearby.
Print all abundant numbers in a small interval.
<?php
function isAbundant(int $num): bool
{
if ($num <= 1) {
return false;
}
$divSum = 0;
for ($i = 1; $i <= intdiv($num, 2); $i++) {
if ($num % $i === 0) {
$divSum += $i;
}
}
return $divSum > $num;
}
echo "Abundant numbers between 1 and 50 are:\n";
for ($value = 1; $value <= 50; $value++) {
if (isAbundant($value)) {
echo $value . " ";
}
}
?> Within 1..50 the abundant values start at 12 and include several even composites. Reusing isAbundant keeps the range scan short and readable.
Reuse the same sum to label each sample number.
<?php
function properDivisorSum(int $n): int
{
if ($n < 2) {
return 0;
}
$total = 0;
for ($i = 1; $i <= intdiv($n, 2); $i++) {
if ($n % $i === 0) {
$total += $i;
}
}
return $total;
}
function classify(int $n): string
{
$s = properDivisorSum($n);
if ($s === $n) {
return "perfect";
}
if ($s < $n) {
return "deficient";
}
return "abundant";
}
foreach ([6, 10, 12, 18, 1] as $value) {
echo $value . ": " . classify($value) . " (s=" . properDivisorSum($value) . ")\n";
}
?> One sum drives three labels. Abundant is the greater-than case; perfect and deficient are equality and less-than.
If n <= 1, return false immediately.
Add i whenever n % i === 0.
Greater means abundant; else not.
Bool for abundant, or a class label.
Trace the proper-divisor sum for n = 12.
| i | 12 % i | Add? | divSum |
|---|---|---|---|
1 | 0 | Yes | 1 |
2 | 0 | Yes | 3 |
3 | 0 | Yes | 6 |
4 | 0 | Yes | 10 |
6 | 0 | Yes | 16 |
divSum 16 is greater than n — abundant.
Where abundant-number checks show up beyond the interview prompt.
Divisor loops and comparison checks.
Example: isAbundant(12).
Label deficient / perfect / abundant.
Example: Example 3.
Find abundant values in a band.
Example: 12..48 in 1..50.
Show what “proper” excludes.
Example: do not add n.
Same sum, equality test.
Example: related topic.
Another divisor-sum pairing problem.
Example: related CTA.
Pro Tip: open with “proper divisors exclude n; abundant means sum > n” before coding.
Why the n/2 scan works well for beginners and interviews.
Dry-run 12 or 18 on paper and watch the sum grow past n.
Stopping at n / 2 avoids adding n by mistake.
Same sum powers deficient/perfect labels.
You can upgrade to sqrt pairing when needed.
Pro Tip: lead with the n/2 scan; mention sqrt pairing only as an optimization aside.
Small habits that keep abundant-number solutions interview-ready.
Proper divisors stop at intdiv($n, 2).
Treat n <= 1 as not abundant.
Mention deficient and perfect alongside abundant.
Use them as quick sanity checks.
sqrt pairing is optional after the clear O(n) version.
Pro Tip: dry-run 6, 10, and 12 — if those three classes match, your sum logic is correct.
Mistakes that commonly break abundant-number programs.
Adding the number itself doubles the definition.
→ Stop at intdiv($n, 2).
Thinking 1 somehow overflows its divisor sum.
→ s(1) = 0; 1 is not abundant.
That would incorrectly count perfect numbers as abundant.
→ Abundant requires a strict greater-than.
Stopping before intdiv($n, 2) misses a valid divisor.
→ Use $i <= intdiv($num, 2).
Checking every n up to millions with O(n) each.
→ Use smaller ranges or faster pairing.
Handle these before claiming the check is complete.
Return false; s(1) = 0 by convention.
Only proper divisor is 1, so sum < n.
Adding n itself breaks the definition.
Use them as sanity checks.
s(6) = 6 — equal, not abundant.
Divisor-pair logic is faster than scanning to n/2.
Handy follow-ups interviewers sometimes ask.
Try these variations to lock in the pattern.
Quick Takeaway: sum proper divisors to n/2; abundant when that sum is greater than n.
| Task | Time | Extra space |
|---|---|---|
| Single check with n/2 scan | O(n) | O(1) |
| Single check with sqrt(n) pairing | O(√n) | O(1) |
| Range scan 1..U (naive) | O(U²) | O(1) |
For interview demos, the O(n) scan is fine; mention pairing when asked about speed.
An abundant number has a proper-divisor sum greater than itself. Loop from 1 to intdiv($n, 2), add every divisor, and check $divSum > $n — remembering that 1 and primes are never abundant.
Practice the three examples above, then continue to amicable numbers for another classic divisor-sum pairing.
s(n) > n means abundant; exclude n from the divisor sum.
Classify divisor sums the interview-friendly way.
s(n) > n
Definitionto n / 2
Loop1 not abundant
Guarddef / perfect
NeighborsO(n) naive
AnalysisThe smallest abundant number is 12 because its proper divisors are 1, 2, 3, 4, 6 and their sum is 16, which is greater than 12.
Learn how to check whether two numbers form an amicable pair in PHP.
9 people found this page helpful