-
Notifications
You must be signed in to change notification settings - Fork 0
/
problem_05.py
31 lines (25 loc) · 1.08 KB
/
problem_05.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
"""https://projecteuler.net/problem=5"""
from functools import reduce
from project_euler.utilities.prime_utils import prime_factorization
def solve(count: int = 20) -> int:
"""Solves problem 5.
The least common multiple of all numbers between 2 and the count
is found by finding the minimum number of prime factors necessary
to form each number between 2 and the count.
Keyword Arguments:
count {int} -- The number of integers to count. (default: {20})
Returns:
int -- The least common multiple of all numbers between 1 and the count.
"""
common_prime_factors = []
for i in range(2, count + 1):
primes = prime_factorization(i)
for j in primes:
if j in common_prime_factors:
if primes.count(j) > common_prime_factors.count(j):
while common_prime_factors.count(j) != primes.count(j):
common_prime_factors.append(j)
break
else:
common_prime_factors.append(j)
return reduce(lambda x, y: x * y, common_prime_factors)