Even Fibonacci Numbers
First read the problem description.
Every third fibonacci number is even. Since \(F_n = F_{n-3} * 4 + F_{n-6}\), we initialy calculate \(F_3\) and \(F_6\) then \(F_9 = F_6 * 4 + F_3\), \(F_{12} = F_9 * 4 + F_6\) etc…
def Fn(Fn_3, Fn_6):
return Fn_3 * 4 + Fn_6
= 0
Fn_6 = 2
Fn_3 sum = Fn_6 + Fn_3
while True:
= Fn(Fn_3, Fn_6)
f if f > 4_000_000:
break
sum += f
= Fn_3
Fn_6 = f Fn_3
Source code of the solution(s):