Start with the clear loop to n // 2. Then list a range, and finish with the faster √n pair method.
Example 1 — Check One Number
Sum proper divisors with a loop to num // 2, then compare with num.
python
def is_abundant(num):
if num <= 1:
return False
total = 0
for i in range(1, num // 2 + 1):
if num % i == 0:
total += i
return total > num
number = 12
if is_abundant(number):
print(f"{number} is an abundant number.")
else:
print(f"{number} is not an abundant number.")
Output
12 is an abundant number.
How It Works
Return False immediately when num <= 1.
Loop i from 1 to num // 2 — no proper divisor is larger.
Add every i that divides num.
For 12 the sum is 16, so total > num is true.
Return that comparison as a boolean.
Example 2 — Abundant Numbers from 1 to 50
Reuse the helper and print every match on one line.
python
def is_abundant(num):
if num <= 1:
return False
total = 0
for i in range(1, num // 2 + 1):
if num % i == 0:
total += i
return total > num
print("Abundant numbers between 1 and 50 are:", end=" ")
for i in range(1, 51):
if is_abundant(i):
print(i, end=" ")
print()
Output
Abundant numbers between 1 and 50 are: 12 18 20 24 30 36 40 42 48
How It Works
Outer loop visits every integer from 1 to 50.
Each value is tested with the same is_abundant helper.
Matches are printed with a trailing space.
The first hit is 12 — a useful self-check.
Keeping the helper pure makes range listing easy.
Example 3 — Sum Divisor Pairs up to √n
For each factor i, also add num // i, but never add num itself.
python
def is_abundant(num):
if num <= 1:
return False
total = 1 # 1 is always a proper divisor for num > 1
i = 2
while i * i <= num:
if num % i == 0:
total += i
partner = num // i
if i != partner:
total += partner
i += 1
return total > num
print(is_abundant(12)) # True — abundant
print(is_abundant(28)) # False — perfect
Output
True
False
How It Works
Start total at 1 because every num > 1 has divisor 1.
Loop while i * i <= num so you only walk up to √n.
When i divides num, add i and also the partner if they differ.
Because the loop starts at 2, the partner is never num itself.
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.
Analysis
Time and Space Complexity
Program
Time
Extra space
Loop to n//2
O(n)
O(1)
Divisor pairs to √n
O(√n)
O(1)
Range 1..N (basic)
O(N²)
O(1)
In interviews, explain the simple loop first, then mention the √n optimization.
Remember
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.