project-euler/122_efficient_exponentiatio...

24 lines
546 B
Python
Raw Normal View History

2023-03-26 17:21:44 +02:00
#!/usr/bin/env python3
from itertools import combinations_with_replacement as comb
bound = 200
sieve = [i-1 for i in range(bound+1)]
dup = []
def rec(chain, sieve, bound, id=0):
c = 1
for m in chain:
n = m+chain[0]
if n > bound:
continue
if len(chain) >= max(sieve[n:n+3]): #<-- trial and error magic
continue
if len(chain) < sieve[n]:
sieve[n] = len(chain)
c += rec([n] + chain, sieve, bound, id+1)
return c
rec([1], sieve, bound)
print(sum(sieve[2:]))