zoukankan      html  css  js  c++  java
  • PE-2 & 暴模...

    题意:

      求不大于4000000的斐波那契数列中,所有偶数之和.

    SOL:

      还是只会暴模...看讨论区貌似有一个很牛逼的大神的发言?

      英语水平太差...

      mark以下

    The Fibonacci sequence is a driven by the second order linear difference equation Fn+2 = Fn+1 + Fn, with boundary conditions F1 = 1, F2 = 1, and thus can be solved exactly. As we know from practice that 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 be 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 is a linear combination of these two solutions 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, 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 are when n is 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 be only a handful of lines long. A slightly further simplification would be to work out Φ^3 and Φ'^3, call them b and b' respectively. Then F3k = (b^k - b'^k)/r for k = 1,2,3...
    
  • 相关阅读:
    理解事件驱动select,poll,epoll三种模型
    谈谈对线程与进程的理解
    5-3.首行缩进
    5-2.行高
    5-1.字间距
    4-6.字体样式重置
    4-5.字体风格
    4-4.字体粗细
    4-3.字体颜色设置
    4-2.字体设置
  • 原文地址:https://www.cnblogs.com/YCuangWhen/p/5316494.html
Copyright © 2011-2022 走看看