project-euler/347_largest_integer.py

30 lines
508 B
Python

#!/usr/bin/env python3
from lib import primegen
from math import log
def maxpw(n, logN):
return int(logN / log(n))
def M(p, q, logN):
return max(q**pw * p**maxpw(p, logN - pw*log(q))
for pw in range(1, maxpw(q, logN - log(p))+1)
)
N = 10**7
logN = log(N)
primes = list(primegen(N//2+1))
s = 0
for i, p in enumerate(primes):
if p > int(N**0.5):
break
for q in primes[i+1:]:
if p*q > N:
break
s += M(p, q, logN)
print(s)