try: from sympy import factorint
except ImportError: factorint = None
try: range = xrange
except NameError: pass
try: from tqdm import trange
except ImportError: trange = range
from collections import Counter
def multiplicity(n, p):
i = 0
while not n % p:
i += 1
n = n // p
return i
def min_factorial(prime, mult):
cnt = 0
for i in range(1, mult + 1):
cnt += multiplicity(i, prime)
if cnt + i >= mult:
return prime * i
def min_factorials_sum(m, n, factorize):
s = 0
for x in trange(m, n + 1):
factors = factorize(x)
s += max(min_factorial(p, m) for p, m in factors.items())
return s
def factorize(n):
factors = []
d = 2
while d * d <= n:
while (n % d) == 0:
factors.append(d)
n //= d
d += 1
if n > 1:
factors.append(n)
return Counter(factors)
m, n = 6, 10
result = min_factorials_sum(m, n, factorint or factorize)
print(result)
dHJ5OiBmcm9tIHN5bXB5IGltcG9ydCBmYWN0b3JpbnQKZXhjZXB0IEltcG9ydEVycm9yOiBmYWN0b3JpbnQgPSBOb25lCgp0cnk6IHJhbmdlID0geHJhbmdlCmV4Y2VwdCBOYW1lRXJyb3I6IHBhc3MKCnRyeTogZnJvbSB0cWRtIGltcG9ydCB0cmFuZ2UKZXhjZXB0IEltcG9ydEVycm9yOiB0cmFuZ2UgPSByYW5nZQoKCmZyb20gY29sbGVjdGlvbnMgaW1wb3J0IENvdW50ZXIKCgpkZWYgbXVsdGlwbGljaXR5KG4sIHApOgogICAgaSA9IDAKICAgIHdoaWxlIG5vdCBuICUgcDoKICAgICAgICBpICs9IDEKICAgICAgICBuID0gbiAvLyBwCiAgICByZXR1cm4gaQoKZGVmIG1pbl9mYWN0b3JpYWwocHJpbWUsIG11bHQpOgogICAgY250ID0gMAoKICAgIGZvciBpIGluIHJhbmdlKDEsIG11bHQgKyAxKToKICAgICAgICBjbnQgKz0gbXVsdGlwbGljaXR5KGksIHByaW1lKQoKICAgICAgICBpZiBjbnQgKyBpID49IG11bHQ6CiAgICAgICAgICAgIHJldHVybiBwcmltZSAqIGkKCgpkZWYgbWluX2ZhY3RvcmlhbHNfc3VtKG0sIG4sIGZhY3Rvcml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