import bisect
bound=10**7
target=bound/2
d=[0]*target
n=2
while n < target:
for i in range(n*n,target,n):
d[i]=d[i]+1
n=n+1
while n < target and d[n]>0:
n=n+1
primeList=[k for k in range(2,target) if d[k]==0]
print "prime list generated"
m=len(primeList)
tick=m/100
s=0
for i in range(m):
k=bisect.bisect(primeList,bound/primeList[i]+1)
for j in range(i+1,k):
p=primeList[i]
r=0
while p*primeList[j] <= bound:
q=primeList[j]
while p*q <= bound:
r=max(r,p*q)
q*=primeList[j]
p*=primeList[i]
s+=r
if i%tick==0:
print i/tick, "percent completed"
print s