Fun Numbers

Python Day 3: Finding Fun Numbers

All the maths fans know the story about 1729, the Ramanujan Number.
One day Hardy visited Ramanujan in the hospital and said he took a taxi with a boring licence number, 1729. Ramanujan said:  it is a very interesting number; it is the smallest number expressible as the sum of two cubes in two different ways.

1729 = 13 + 123 = 93 + 103

We will find some interesting number, the sum of divisors’ square number, and perfect number with python.



Perfect Number:

perfect number is a positive integer that is equal to the sum of its proper positive divisors

Example: the proper divisor of 6 is 1,2,3 and 6 = 1+2+3.

Python code:

#we want to find all the perfect number within 1000.

sieve= [1]*(1000+1)

n = 2
while n <= 1000:
    # check n
    if sieve[n] == n:
        print(n, "is a perfect number")
    # add n to all k * n where k > 1
    kn = 2 * n
    while kn <= 1000:
        sieve[kn] += n
        kn += n
    n += 1


6 is a perfect number
28 is a perfect number
496 is a perfect number

We can see 6,28 and 496 are perfect numbers.


InspiredImages / Pixabay


The sum of divisors’ square number:

Suppose we want to find some number such that the Sum of the squares of the number’s divisors is a perfect square number


The divisors of 42 are 1,2,3,6,7,14,21,42

the square of divisors are 1,4,9,36,49, 196, 441, 1764

Sum of the square of divisors are 1+4+9+ 36+49+196+441+1764=2500

2500=500 * 500 is a perfect square

Python Code:

def list_squared(m,n):
    for i in range(m,n+1):
        for j in range(1,int(i**0.5)+1):
            if i%j==0:
                if j!=div:
        if int(sqt)==sqt:
    return list



[[42, 2500.0], [246, 84100.0]]

We can see 42, and 246 satisfy the conditions in the range (42,250)


I like Number theory because I feel it entitled every number a meaning 🙂 In recent years, my friends and I got a little sensitive and sentimental about our ages. However, when i look at the numbers, every year is beautiful indeed:

27, the Cube  age,
28, the Perfect  age,
29, a Gaussian  age,
30, a smallest 2,3,5, divisor age,
31, a PRIME age,
32, a Binary age!!!

I like my number theory classmate JOHNES said: 

Appreciated every little things in life, like Tuesdays, it only comes once a week! 

Happy Studying! 🐼


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Social media & sharing icons powered by UltimatelySocial
%d bloggers like this: