Check Abundant Number in PHP

Beginner
⏱️ 12 min read
📚 Updated: May 2026
🎯 2 Code Examples
Number theory

What you’ll learn

  • What an abundant number means in simple words.
  • How to find proper divisors and their sum.
  • One PHP program to check a single number and one to print a range.
  • Edge cases, complexity, and interview-ready explanation points.

Overview

A number is abundant if its proper divisors add up to more than the number itself. This page gives clean, readable PHP code with clear logic so even beginners can explain it confidently.

Prerequisites

You only need basic PHP syntax to follow this page.

  • for loop, if condition, and modulo operator %.
  • Basic functions and echo output.
  • Understanding of divisors (numbers that divide exactly).

Quick examples

12Abundant
Proper divisors
1, 2, 3, 4, 6
Sum
16 > 12
6Perfect
Proper divisors
1, 2, 3
Sum
6 = 6
7Not abundant
Proper divisors
1
Sum
1 < 7

Live preview

Type a value to see its proper divisors, their sum, and final verdict.

Use whole numbers n ≥ 1.

Live result
Press "Run check" to see details.

Algorithm

Goal: find the sum of proper divisors and check if that sum is greater than n.

Handle tiny values

If n <= 1, return false.

Start sum at zero

Create $divSum = 0.

Scan divisors

Loop from 1 to intdiv($n, 2). If $n % $i === 0, add $i to $divSum.

Compare

If $divSum > $n, it is abundant; otherwise not abundant.

📜 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
1

Check one number

php
<?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.";
}
?>
2

Print abundant numbers from 1 to 50

php
<?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 . " ";
    }
}
?>

🔄 Input / output examples

Input nTypical result
1212 is an abundant number.
1818 is an abundant number.
77 is not an abundant number.
11 is not an abundant number.

❓ FAQ

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.
Start with the simple method (easy to understand), then mention the sqrt optimization using divisor pairs for better performance.

Edge cases

n <= 1

Return false

These are not abundant in this tutorial definition.

Prime n

Always not abundant

Prime numbers only have one proper divisor (1).

Large n

Use sqrt optimization

For very large values, divisor-pair logic is faster than scanning to n/2.

⏱️ Time and space complexity

ApproachTimeExtra space
Basic loop to n/2O(n)O(1)
Divisor pairs up to sqrt(n)O(√n)O(1)

Summary

  • Definition: abundant means sum of proper divisors is greater than the number.
  • Code: loop through divisors, add them, compare with n.
  • Interview tip: explain basic and optimized methods.
Did you know?

The 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.

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