project-euler/140_modified_fibonacci_gold...

32 lines
608 B
Python
Raw Normal View History

2023-03-26 17:21:44 +02:00
#!/usr/bin/env python3
def sols():
"""yields int solutions of a**2 - 5 b**2 = 1"""
a, b = 9, 4
while True:
yield a, b
a, b = 9*a + 20*b, 4*a + 9*b
def cs():
"""yields int solutions of a in a**2 - 5 b**2 = 44"""
base_sols = [(7, 1), (8, 2), (13, 5), (17, 7), (32, 14), (43, 19)]
base_sols.reverse()
for a, b in sols():
for a0, b0 in base_sols:
yield a0 * a - 5 * b0 * b
N = 30
gen = cs()
next(gen)
nuggs = []
while len(nuggs) < N:
c = next(gen)
if (c - 7) % 5 != 0:
continue
nuggs.append((c-7) // 5)
print(sum(nuggs))