-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp005.py
43 lines (35 loc) · 925 Bytes
/
p005.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python
"""
Smallest multiple
Problem 5
2520 is the smallest number that can be divded by each of the numbers from
1 to 10 without any remainder.
What is the smallest positive number that is evenly divisible by all the numbers from 1 to 20?
"""
def primeFactors(n):
primefactors = []
i = 2
while i*i<=n:
if n%i:
i += 1
else:
n //= i
primefactors.append(i)
if n>1:
primefactors.append(n)
return primefactors
numDivisors = 20
minfactors = {}
for i in range(1, numDivisors+1):
primefactors = primeFactors(i)
for key in primefactors:
val = primefactors.count(key)
if key in minfactors:
if minfactors[key] < val:
minfactors[key] = val
else:
minfactors[key] = val
product = 1
for key, val in minfactors.items():
product *= (key**val)
print(product)