2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.

What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?

The approach will be the following:

- Create a list of all the factors of the numbers from 1 to 20
- Obtain all the different factors. Get the equal factors with the greatest exponent
- Multiply the factors: this is the solution

Functions for obtaining all the factors of a number

```
In [57]:
```def factor(N):
for i in range(2,N):
if (N % i == 0):
return i
return 0
def decompose(N):
f = factor(N)
lf = []
while f > 0:
lf.append(f)
N = N / f
#print("Factor: {}, Rest: {}".format(f, N)) #-- Debuging
f = factor(N)
lf.append(N)
#-- Create a dictionary with the factors and exponents
d = {}
for f in lf:
try:
d[f] += 1
except:
d[f] = 1
return d

Checking the function

```
In [58]:
```for i in range(2,21):
print("{}: {}".format(i, decompose(i)))

```
```

```
In [76]:
```df = {}
for i in range(2,21):
d = decompose(i)
for f in d.keys():
try:
df[f] = max(df[f], d[f])
except:
df[f] = 1

Finally, al the factors should be multiplied between them to obtaing the solution

```
In [77]:
```n = 1
for f in df.keys():
n = n * (f ** df[f])

```
In [78]:
```print("The solution is: {}".format(n))

```
```

```
In [ ]:
```