- Proper divisors
- 1, 2, 3, 4, 6
- Sum
- 16 > 12
Check Abundant Number in Python
What you’ll learn
- What an abundant number means in easy words.
- How to find proper divisors and their sum.
- One Python program to check a single number and one to print a range.
- Common edge cases, interview tips, and complexity.
Overview
A number is abundant if its proper divisors add up to more than the number itself. This page shows the exact steps and gives clean Python code you can explain in school or interviews.
Quick examples
- Proper divisors
- 1, 2, 3
- Sum
- 6 = 6
- Proper divisors
- 1
- Sum
- 1 < 7
Live preview
Type a number to see its proper divisors and final verdict.
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 div_sum = 0.
Scan divisors
Loop from 1 to n // 2. If n % i == 0, add i to div_sum.
Compare
If div_sum > n, it is abundant; otherwise it is not.
📜 Pseudocode
function isAbundant(n):
if n <= 1:
return false
div_sum = 0
for i from 1 to floor(n / 2):
if n mod i == 0:
div_sum = div_sum + i
return div_sum > n Check one number
def is_abundant(num: int) -> bool:
if num <= 1:
return False
div_sum = 0
for i in range(1, num // 2 + 1):
if num % i == 0:
div_sum += i
return div_sum > num
number = 12
if is_abundant(number):
print(f"{number} is an abundant number.")
else:
print(f"{number} is not an abundant number.") Print abundant numbers from 1 to 50
def is_abundant(num: int) -> bool:
if num <= 1:
return False
div_sum = 0
for i in range(1, num // 2 + 1):
if num % i == 0:
div_sum += i
return div_sum > num
print("Abundant numbers between 1 and 50 are:")
for value in range(1, 51):
if is_abundant(value):
print(value, end=" ") ❓ FAQ
Edge cases
Return False
These are not abundant in this tutorial definition.
Always not abundant
Primes have only one proper divisor (1).
Use sqrt optimization
For very large values, divisor-pair logic is faster than scanning to n//2.
⏱️ Time and space complexity
| Approach | Time | Extra space |
|---|---|---|
| Basic loop to n//2 | O(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 both basic and sqrt methods.
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.
9 people found this page helpful
