PE-2 & Critical mode ...

Source: Internet
Author: User
Tags square root

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 ...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.