project-euler/0005.py
2018-03-28 20:48:35 +02:00

35 lines
769 B
Python

from collections import Counter
from functools import reduce
import util
target = 232792560
def smallest_multiple(nbrs):
factors = None
# get the prime factors of all nbrs, and keep the highest occurence of each unique prime factor
# in each number
for num in nbrs:
nums = util.find_prime_factors(num)
count = Counter(nums)
if (factors == None):
factors = count
else:
for key, value in count.items():
if (not factors[key] or value > factors[key]):
factors[key] = value
result = 1
for key, value in factors.items():
result *= key ** value
return result
result = smallest_multiple(range(1, 21))
print(result)
print(result == target)