Abundant Numbers

Find abundant numbers (sum of proper divisors > number).

AdvancedPhase 6 - Category 1: Number LogicExample 9 of 10
abundant-numbers.py
1# Find abundant numbers
2print("Abundant numbers 1-100:")
3
4for num in range(1, 101):
5 divisor_sum = 0
6 for i in range(1, num):
7 if num % i == 0:
8 divisor_sum += i
9
10 if divisor_sum > num:
11 print(num, end=" ")
12print()

Output

Abundant numbers 1-100:
12 18 20 24 30 36 40 42 48 54 ...

What's going on

Check if sum of proper divisors exceeds number.

Key Concepts:

Find all proper divisors
Sum them
Compare with number