Hunt some strange numbers with Python.

fredysomy

Fredy Somy

Posted on December 10, 2020

Hunt some strange numbers with Python.

We have heard about Different types of numbers and series.
For example Ramanujan Number, is the smallest number which can be expressed as the sum of two different cubes in two different ways.

Today we are going to see some another strange types of numbers and how to generate it with Python.

How strange!

Lets take a look at this number ..
The number 2520 looks like a normal number like other numbers, but it is not like that.
The strange thing is that it is divisible by numbers from 1 to 10, whether these numbers are odd or even !!

Lets see:

2520 ÷ 1 = 2520
2520 ÷ 2 = 1260
2520 ÷ 3 = 840
2520 ÷ 4 = 630
2520 ÷ 5 = 504
2520 ÷ 6 = 420
2520 ÷ 7 = 360
2520 ÷ 8 = 315
2520 ÷ 9 = 280
2520 ÷ 10 = 252

See its awesome... But there is many more numbers like that.
Example: 5040,7560


Lets find more numbers like this by the way we Programmers do ..
We are going to do it Programmatically with Python 🐍

Lets get started.

Aim:

  • Find numbers which are divisible by numbers from 1-10

Code:

def check(id: int):
    for i in range(1,id):
        check= 0
        for j in range(1,11):
            if i%j==0:
                check= check+1
        if check==10:
            print(i)


check(100000)               


Enter fullscreen mode Exit fullscreen mode

The Code is simple.

  • We are getting numbers from 1-100000(here) using for loop and range.
  • We are initialising a variable to check for divisibility.
check=0
for j in range(1,11):
    if i%j==0:
        check= check+1
if check==10:
     print(i)
Enter fullscreen mode Exit fullscreen mode
  • In the for loop we are checking the divisibility of the number with each numbers from 1-10.
  • If a number is divisible the it will increment check by 1.
  • Finaly we check if variable check is equal to 10 ( Means that the numbers is divisible by each in 1-10)

Final Output:

2520
5040
7560
10080
12600
15120
17640
20160
22680
25200
27720
30240
32760
35280
37800
40320
42840                                         45360
47880
50400
52920                                         55440
57960
60480
63000
65520
68040
70560
73080
75600
78120
80640
83160
85680
88200
90720
93240
95760
98280
Enter fullscreen mode Exit fullscreen mode

That is for today guys .Thanks for reading the blog.

💖 💪 🙅 🚩
fredysomy
Fredy Somy

Posted on December 10, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Hunt some strange numbers with Python.