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.

GraphicMama-team / Pixabay
Perfect Number:
a 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
Result:
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
Example:
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): list=[] for i in range(m,n+1): sum=0 s_list=[] for j in range(1,int(i**0.5)+1): if i%j==0: div=i/j sum+=j**2 if j!=div: sum+=div**2 sqt=sum**0.5 if int(sqt)==sqt: s_list=[i,sum] list.append(s_list) return list list_squared(42,250)
Output:
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! 🐼