Solve 133 and 134.
This commit is contained in:
40
python/e134.py
Normal file
40
python/e134.py
Normal file
@@ -0,0 +1,40 @@
|
||||
from lib_prime import primes
|
||||
from math import log, ceil
|
||||
|
||||
|
||||
def s(p1, p2):
|
||||
p1l = ceil(log(p1, 10))
|
||||
base = 10**p1l
|
||||
for lhs in range(base, 10**12, base):
|
||||
r = lhs + p1
|
||||
if r % p2 == 0:
|
||||
return r
|
||||
assert False
|
||||
|
||||
|
||||
def s2(p1, p2):
|
||||
# Invert, always invert ;)
|
||||
p1l = ceil(log(p1, 10))
|
||||
base = 10**p1l
|
||||
c = p2
|
||||
while True:
|
||||
if c % base == p1:
|
||||
return c
|
||||
c += p2
|
||||
|
||||
|
||||
def euler_134():
|
||||
r = 0
|
||||
ps = primes(10**6 + 10) # p1 < 10**6 but p2 is the first p > 10**6
|
||||
for i in range(2, len(ps) - 1):
|
||||
p1, p2 = ps[i], ps[i + 1]
|
||||
sc = s(p1, p2)
|
||||
r += sc
|
||||
return r
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
solution = euler_134()
|
||||
print("e134.py: " + str(solution))
|
||||
assert solution == 18613426663617118
|
||||
|
||||
Reference in New Issue
Block a user