Test instructions
The sum of all even numbers in the Fibonacci sequence not exceeding 4000000.
SOL:
Or just a critical mode ... Look at the discussion area there seems to be a very good God's speech?
The English level is too poor ...
Mark below
The Fibonacci sequence is a driven by the second order linear difference equation fn+2 = fn+1 + Fn, with boundary conditio NS F1 = 1, F2 = 1, and thus can be solved exactly. As we know from practice the FN is roughly exponential, we try Fn = Aa^n for A and a constants. This gives the quadratic a^2 = a + 1, which happens to being the equation for the Golden ratioφ, and its inverse which I ' ll Denoteφ ' (i.e.φ ' = 1/φ,φ ' =φ-1) as the equation is second order then it's a linear combination of these NS and the boundary conditions define the constants involved, i.e. Fn = aφ^n + bφ ' ^n F0 = 0 (easy if you follow backwards) So A + B = 0 F1 = 1. usingφ= (1 + R)/2 andφ ' = (1-r)/2 where R is the positive square root of 5, and you can find A-B = 2/r yielding A = 1/r , B = -1/r so Fn = (φ^n/r)-(Φ ' ^n/r) = (φ^n-φ ' ^n)/R for all n. As can be seen, the even terms was when N was a multiple of 3, so using this formula add F3 + F6 + ... until you get a term Greater than one million. ThUS a program for this could is only a handful of lines long. A slightly further simplification would is to work outφ^3 andφ ' ^3, call them B and B ' respectively. Then f3k = (b^k-b ' ^k)/r for k = ...
PE-2 & Critical mode ...