project-euler/549_divisibility_of_factori...

31 lines
524 B
Python

#!/usr/bin/env python3
def modpw(n, p):
r = 0
while n >= p:
r += n // p
n //= p
return r
n = 10**8 + 1
sieve = [0] * n
for p in range(2, n):
if sieve[p] > 0:
continue
minN = p
frompw = 1
topw = 2
k = 1
while k*p < n:
for pw in range(frompw, topw):
k *= p
for m in range(k, n, k):
sieve[m] = max(sieve[m], minN)
minN += p
frompw = topw
topw = modpw(minN, p) + 1
print(sum(sieve[2:]))