from sympy import divisor_count
from sortedcontainers import SortedDict
u=10**8
k=10**5
threshold=10*k
d=SortedDict()
for n in range(1,k):
d[divisor_count(n)]=n
res=0
for n in range(k,u+1):
d[divisor_count(n)]=n
while d.peekitem()[1] < n-k+1:
d.popitem()
res+=d.peekitem()[0]
if n%k==0:
print(f"{n//k}/1000 completed, current result: {res}" )
if len(d)>threshold:
for i,(j,v) in enumerate(d.items()):
if v < n-k+1:
d.popitem(index=i)
print(res)