Number 2520?

number-2520Did you know that 2520 is the smallest number exactly divisible by all integers from 1 to 10.

The aim of this challenge is to write a python script to work out this number from its definition.

Note that a number (a) is exactly divisible (whole division) by another number (b) if the remainder of divising a per b is equal to 0.

In pseudo code:

In Python the MOD operator (remainder) is %.

We are going to use this operator in our code to find out the smallest number exactly divisible by all integers from 1 to 10.

Note that we know, per definition, that this number will have to be greater or equal to 10. So, using an iterative approach (in this case, a while loop) we will test every number from 10, one at a time up until we find a number that is divisible by all the numbers from 1 to 10.

Flowchart


Here is the flowchart of our algorithm:
number-2520-flowchart

Python Code


You can use the above flowchart to recreate the Python code in the trinket window below:

Did you like this challenge?

Click on a star to rate it!

Average rating 4 / 5. Vote count: 1

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!

Tagged with: