40 lines
999 B
Python
40 lines
999 B
Python
|
from lib_prime import primes
|
||
|
from typing import Optional, Tuple
|
||
|
|
||
|
|
||
|
def s(n):
|
||
|
ps = primes(n)
|
||
|
|
||
|
sum = 0
|
||
|
for p1_index in range(len(ps)):
|
||
|
p1 = ps[p1_index]
|
||
|
for p2_index in range(p1_index + 1, len(ps)):
|
||
|
p2 = ps[p2_index]
|
||
|
if p1 * p2 > n:
|
||
|
break
|
||
|
largest: Optional[Tuple[int, int, int]] = None
|
||
|
p1e = 1
|
||
|
while p1**p1e * p2 <= n:
|
||
|
p2e = 1
|
||
|
m = p1**p1e * p2**p2e
|
||
|
while m <= n:
|
||
|
if largest is None or m > largest[2]:
|
||
|
largest = (p1, p2, m)
|
||
|
p2e += 1
|
||
|
m = p1**p1e * p2**p2e
|
||
|
p1e += 1
|
||
|
assert largest is not None
|
||
|
sum += largest[2]
|
||
|
return sum
|
||
|
|
||
|
|
||
|
def euler_347():
|
||
|
assert s(100) == 2262
|
||
|
return s(10_000_000)
|
||
|
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
solution = euler_347()
|
||
|
print("e347.py: " + str(solution))
|
||
|
assert solution == 11109800204052
|