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.
Example: the proper divisor of 6 is 1,2,3 and 6 = 1+2+3.
#we want to find all the perfect number within 1000. sieve= *(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.
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
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)
[[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! 🐼