斐波那契数列推导及应用

来源:互联网 发布:大数据专业课程设置 编辑:程序博客网 时间:2024/05/16 18:08

首先:
a_{n+2}=a_{n+1}+a_{n}
等价于

a_{n+2}- \frac{1-\sqrt{5} }{2} a_{n+1}= \frac{1+\sqrt{5} }{2}\left(a_{n+1}- \frac{1-\sqrt{5} }{2}a_{n} \right)  ..................(1)
等价于
a_{n+2}- \frac{1+\sqrt{5} }{2} a_{n+1}= \frac{1-\sqrt{5} }{2}\left(a_{n+1}- \frac{1+\sqrt{5} }{2}a_{n} \right)  ..................(2)


然后:

由(1)(2)递推得
a_{n+2}- \frac{1-\sqrt{5} }{2} a_{n+1}=\left(  \frac{1+\sqrt{5} }{2} \right) ^{n}*A ........................(3)

a_{n+2}- \frac{1+\sqrt{5} }{2} a_{n+1}=\left(  \frac{1-\sqrt{5} }{2} \right) ^{n}*B ........................(4)
其中A,B为常数,由a_{1},a_{2}确定


最后:
由(3)(4)解二元一次方程组得:

a_{n+2}=\left(  \frac{1-\sqrt{5} }{2} \right) ^{n}*C+\left(  \frac{1+\sqrt{5} }{2} \right) ^{n}*D
其中C,D为常数,由a_{1},a_{2}确定
转载:https://www.zhihu.com/question/25217301/answer/30247743
来源:知乎


nefu 462

题目:http://acm.nefu.edu.cn/JudgeOnline/problemshow.php?problem_id=462



可以先写一个找找f(2n)和n的关系:
#include<stdio.h>#include<string.h>#include<math.h>#include<algorithm>#define ll long longusing namespace std;int main(){    ll a,b,c;    ll fib[51];    fib[1]=1;    fib[2]=1;    for(int i=3;i<=50;i++)        fib[i]=fib[i-1]+fib[i-2];    for(int i=3;i<=50;i++)        if(fib[2*i]%8==0)        printf("%d  %lld\n",i,fib[i]);    return 0;}

        


可以发现能被3整除即可。
于是
#include <iostream>    using namespace std;      int main(){      int n;      while(cin>>n){          if(n%3)              cout<<"no"<<endl;          else              cout<<"yes"<<endl;      }      return 0;  }



原创粉丝点击