Skip to content

Commit 70def15

Browse files
Update sol1.py
1 parent 88c438f commit 70def15

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

project_euler/problem_095/sol1.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,17 @@
2828
- Iterate over found some factors to find longest chain
2929
"""
3030

31-
from math import isqrt
31+
from math import isqrt, prod
3232

3333

34-
def sum_primes(factor_d, num):
34+
def sum_primes(primes_degrees: dict[int, int], num: int) -> int:
3535
"""
3636
Calculates the sum of factors from all prime exponents.
3737
38-
>>> sum_primes({2: 1, 3: 1}, 6)
38+
>>> sum_primes(primes_degrees={2: 1, 3: 1}, num=6)
3939
6
4040
"""
41-
tot = 1
42-
for p in factor_d:
43-
comp = 0
44-
ex_factor = 1
45-
for _ in range(factor_d[p] + 1):
46-
comp += ex_factor
47-
ex_factor *= p
48-
tot *= comp
49-
return tot - num
41+
return prod((prime ** (degree + 1) - 1) // (prime - 1) for prime, degree in primes_degrees.items()) - num
5042

5143

5244
def generate_primes(n: int):

0 commit comments

Comments
 (0)